Bug 60010

Summary: SXSSFWorkbook.write() fails when the template is based on PackageAccess.READ OPCPackage
Product: POI Reporter: Yavor <javornik.lists>
Component: SXSSFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal CC: noemi.szemenyei
Priority: P2    
Version: 3.14-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Yavor 2016-08-16 21:52:54 UTC
Observed behavior:
When a SXSSFWorkbook workbook is created from a template which is "read-only" (initiated with PackageAccess.READ mode OPCPackage), then writing that workbook to another file is failing.

Expected behavior:
Since the SXSSFWorkbook is written to another file - it should be possible to save it even when the template has been open in read only mode.


Stack trace:
Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidOperationException: Operation not allowed, document open in read only mode!
        at org.apache.poi.openxml4j.opc.OPCPackage.throwExceptionIfReadOnly(OPCPackage.java:520)
        at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:943)
        at org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:522)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.commit(XSSFWorkbook.java:1687)
        at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:464)
        at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:211)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:939)
        at jvdemos.poi.PoiDemo.testPoi(PoiDemo.java:31)
        at jvdemos.poi.PoiDemo.main(PoiDemo.java:47)

Code:
 20         OPCPackage pkg = OPCPackage.open(templateFilename, PackageAccess.READ);
 21         XSSFWorkbook template = new XSSFWorkbook(pkg);
 22         // pkg.revert();
 23         // pkg.close();
 24         // in.close();
 25
 26         SXSSFWorkbook workbook = new SXSSFWorkbook(template, 100);
 28         fillData(workbook);
 30         FileOutputStream out = new FileOutputStream("/tmp/out1.xlsx");
 31         workbook.write(out);
 32         out.close();
Comment 1 Nick Burch 2016-08-16 21:55:30 UTC
Can you try with a recent nightly build / build from svn / build from git / wait a few more days and try with POI 3.15 beta 3 when out? Only we've fixed some bugs around this sort of thing since 3.14 final, so it may already be solved
Comment 2 Yavor 2016-08-16 22:20:29 UTC
I just tried with the nightly build poi-bin-3.15-beta4-20160815.tar.gz - it fails too:
Exception in thread "main" org.apache.poi.openxml4j.exceptions.InvalidOperationException: Operation not allowed, document open in read only mode!
	at org.apache.poi.openxml4j.opc.OPCPackage.throwExceptionIfReadOnly(OPCPackage.java:585)
	at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:1008)
	at org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:521)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.commit(XSSFWorkbook.java:1765)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:486)
	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:236)
	at org.apache.poi.xssf.streaming.SXSSFWorkbook.write(SXSSFWorkbook.java:941)
Comment 3 Nick Burch 2016-09-12 23:12:25 UTC
Disabled unit test added to TestSXSSFWorkbook in r1760458. Because of the way that SXSSF sits on top of XSSF, it might not be a very quick fix. However, with any luck the changes needed for finishing in-place write support may solve this case too