You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2021/01/13 11:20:32 UTC
[Bug 65077] New: Workbook.close() clears the second (the last) sheet
data in previously saved file
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: dev@poi.apache.org
Reporter: grigorievan@netcracker.com
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 65077] Workbook.close() clears the second (the last) sheet data
in previously saved file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65077
Andrey Grigoriev <gr...@netcracker.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #1 from Andrey Grigoriev <gr...@netcracker.com> ---
There was wrong example. Please use this one:
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();
}
rowNumber = 0;
cellNumber = 0;
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));
}
}
Files.delete(Paths.get(outFile.getPath()));
try (FileOutputStream out = new FileOutputStream(outFile)) {
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 65077] Workbook.close() clears the second (the last) sheet data
in previously saved file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65077
PJ Fanning <fa...@yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #3 from PJ Fanning <fa...@yahoo.com> ---
*** This bug has been marked as a duplicate of bug 58779 ***
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 65077] Workbook.close() clears the second (the last) sheet data
in previously saved file
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65077
--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
It is not intuitive but the current POI behaviour is that if you create an
XSSFWorkbook based on a file, that that file is modified when you make changes
to the XSSFWorkbook. If you create an SXSSFWorkbook that is based on an
XSSFWorkbook, then the modifications to the SXSSFWorkbook affect the
XSSFWorkbook and this in turn affects the file.
If you want use an xlsx file as a template in SXSSFWorkbook but not modify the
original file, then you need to create the XSSFWorkbook using an InputStream.
When an InputStream is used, modifications to XSSFWorkbook do not affect the
original data source (eg a file).
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org