Bug 56557 - Output file get corrupted with SXSSFWorkbook and "chart sheet"
Summary: Output file get corrupted with SXSSFWorkbook and "chart sheet"
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-23 11:28 UTC by jobe
Modified: 2017-06-20 14:02 UTC (History)
2 users (show)



Attachments
testfile with chart sheet (12.17 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2014-05-23 11:28 UTC, jobe
Details

Note You need to log in before you can comment on or make changes to this bug.
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"...