https://bz.apache.org/bugzilla/show_bug.cgi?id=65077
Bug ID: 65077
Summary: Workbook.close() clears the second (the last) sheet
data in previously saved file
Product: POI
Version: 4.1.1-FINAL
Hardware: PC
Status: NEW
Severity: major
Priority: P2
Component: SXSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Created attachment 37703
--> https://bz.apache.org/bugzilla/attachment.cgi?id=37703&action=edit
example source file
Hi guys,
In the following example second invocation of Workbook.close() produces file
test2.xlsx with two sheets, but the second has no data.
Also observed: the first file has size of 32,952 bytes and the second one has
61,619 bytes.
int rowNumber = 0;
int cellNumber = 0;
String outputFileName = "c:/temp/test1.xlsx";
File outFile = new File(outputFileName);
File outFile2 = new File("c:/temp/test2.xlsx");
Workbook workbook = new SXSSFWorkbook(100);
try {
Sheet sheet = workbook.createSheet("Sheet1");
Row row = null;
for (int i = 0; i < 1000; i++) {
row = sheet.createRow(rowNumber++);
cellNumber = 0;
for (int j = 1; j <= 10; j++) {
Cell cell = row.createCell(cellNumber++);
cell.setCellValue(String.valueOf(j));
}
}
try (FileOutputStream out = new FileOutputStream(outFile)) {
workbook.write(out);
}
} finally {
workbook.close();
((SXSSFWorkbook) workbook).dispose();
}
workbook = new SXSSFWorkbook((XSSFWorkbook)
WorkbookFactory.create(outFile), 100);
try {
Sheet sheet = workbook.createSheet("Sheet2");
Row row = null;
for (int i = 0; i < 1000; i++) {
row = sheet.createRow(rowNumber++);
cellNumber = 0;
for (int j = 1; j <= 10; j++) {
Cell cell = row.createCell(cellNumber++);
cell.setCellValue(String.valueOf(j));
}
}
try (FileOutputStream out = new FileOutputStream(outFile2)) {
workbook.write(out);
}
} finally {
workbook.close();
((SXSSFWorkbook) workbook).dispose();
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]