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.
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
Both 3.10 and 3.14 are somewhat old now, I'd suggest you try upgrading
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.
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.
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();
Improved the unit test in r1799304
Thanks for fixing this, it should have been "readOnly: true"...