本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFWorkbook.close方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFWorkbook.close方法的具體用法?Java XSSFWorkbook.close怎麽用?Java XSSFWorkbook.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFWorkbook
的用法示例。
在下文中一共展示了XSSFWorkbook.close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeXLSXFile
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static void writeXLSXFile() throws IOException {
// @SuppressWarnings("resource")
XSSFWorkbook wbObj = new XSSFWorkbook();
XSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
XSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
XSSFCell cell = rowObj.createCell(col);
cell.setCellValue(rowData.get(col));
logger.info("Writing " + row + " " + col + " " + rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例2: parse
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
/**
* Parses an inputstream containin xlsx into an outputStream containing XML
*
* @param inputStream
* the source
* @param outputStream
* the result
* @throws IOException
* @throws XMLStreamException
*/
public void parse(final InputStream inputStream, final OutputStream outputStream)
throws IOException, XMLStreamException {
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XMLStreamWriter out = this.getXMLWriter(outputStream);
out.writeStartDocument();
out.writeStartElement("workbook");
int sheetCount = workbook.getNumberOfSheets();
for (int i = 0; i < sheetCount; i++) {
final XSSFSheet sheet = workbook.getSheetAt(i);
try {
this.export(sheet, out);
} catch (UnsupportedEncodingException | FileNotFoundException | XMLStreamException
| FactoryConfigurationError e) {
e.printStackTrace();
}
}
out.writeEndElement();
out.writeEndDocument();
out.close();
workbook.close();
}
示例3: leerCiudadanos
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public ArrayList<Ciudadano> leerCiudadanos(ArrayList<Ciudadano> ciudadanos, String ruta) {
try {
FileInputStream file = new FileInputStream(new File(ruta));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
ArrayList<Object> aux = new ArrayList<Object>();
for (int i = 0; i < 7; i++) {
aux.add(row.getCell(i) != null ? row.getCell(i).toString() : null);
}
String nombre = row.getCell(0) != null ? row.getCell(0).toString() : null;
if (nombre != null && nombre.equals("Nombre"))
continue;
String fecha = row.getCell(3) != null ? row.getCell(3).toString() : null;
Date date = new SimpleDateFormat("dd-MMM-yyyy").parse(fecha);
java.sql.Date nacimiento = new java.sql.Date(date.getTime());
Ciudadano ciudadano = new Ciudadano(aux.get(0).toString(), aux.get(1).toString(), aux.get(2).toString(),
aux.get(4).toString(), aux.get(5).toString(), aux.get(6).toString(), nacimiento);
ciudadanos.add(ciudadano);
}
file.close();
workbook.close();
} catch (Exception e) {
System.err.println("Error al leer del excel xlsx");
}
return ciudadanos;
}