[Bug 65077] New: Workbook.close() clears the second (the last) sheet data in previously saved file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug 65077] New: Workbook.close() clears the second (the last) sheet data in previously saved file

Bugzilla from bugzilla@apache.org
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: [hidden email]
          Reporter: [hidden email]
  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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 65077] Workbook.close() clears the second (the last) sheet data in previously saved file

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=65077

Andrey Grigoriev <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Andrey Grigoriev <[hidden email]> ---
 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: [hidden email]
For additional commands, e-mail: [hidden email]