Bug 56557

Summary: Output file get corrupted with SXSSFWorkbook and "chart sheet"
Product: POI Reporter: jobe <jonas.berglin>
Component: SXSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: jonas.berglin, maligang1
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: testfile with chart sheet

Description jobe 2014-05-23 11:28:42 UTC
Created attachment 31653 [details]
testfile with chart sheet

With SXSSFWorkbook the stored file gets corrupted if it contains a "chart sheet". 

This very simple code snippet reproduces the error:

<..>
  Workbook wb = WorkbookFactory.create(new File("in.xlsx"));
		
  // Using streaming XSSFWorkbook makes the output file invalid
  wb = new SXSSFWorkbook(((XSSFWorkbook) wb));
	    
  FileOutputStream out = new FileOutputStream("out.xlsx");
  wb.write(out);
  out.close();
<..>

I have attached an empty excel-file with two empty sheets, one normal sheet and one chart sheet, which can be used test.

This is similar to the Bug 49472, which was present in ealier versions.
Comment 1 ligang 2017-06-15 09:49:56 UTC
Same problem in my project.
I checked the corrupted file by unzip it,and I found some useful imformation.
The xml file under xl\chartsheets had an additionnal elememt named <sheetData>,which should not exist in a type of chartsheet.
I think this is a bug .

my poi version is 3.14
Comment 2 ligang 2017-06-15 12:51:09 UTC
Same problem in my project.
I checked the corrupted file by unzip it,and I found some useful imformation.
The xml file under xl\chartsheets had an additionnal elememt named <sheetData>,which should not exist in a type of chartsheet.
I think this is a bug .

my poi version is 3.14
Comment 3 Nick Burch 2017-06-15 13:00:33 UTC
Both 3.10 and 3.14 are somewhat old now, I'd suggest you try upgrading
Comment 4 ligang 2017-06-16 02:06:25 UTC
3.16 is (In reply to Nick Burch from comment #3)
> Both 3.10 and 3.14 are somewhat old now, I'd suggest you try upgrading

tried 3.16 , same problem occur.
Comment 5 ligang 2017-06-16 09:24:53 UTC
I have modified the method
org.apache.poi.xssf.streaming.SXSSFWorkbook.injectData(File, OutputStream)
at line 354.

---
if(xSheet!=null)
->
if(xSheet!=null && !(xSheet instanceof XSSFChartSheet))
---

Since there is no <sheetData> in a chartsheet, XSSFChartSheet should not take this if branch.(copyStreamAndInjectWorksheet(is,zos,xis) process the field <sheetData>)


The trick works fine in my case.
Comment 6 Dominik Stadler 2017-06-16 12:00:00 UTC
Applied now on trunk via r1798913

The following in a test-case also showed the problem via some invalid XML structure that was produced.

        Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
        assertNotNull(wbBack);
        wbBack.close();
Comment 7 Javen O'Neal 2017-06-20 06:09:48 UTC
Improved the unit test in r1799304
Comment 8 Dominik Stadler 2017-06-20 14:02:36 UTC
Thanks for fixing this, it should have been "readOnly: true"...