Bug 60010 - SXSSFWorkbook.write() fails when the template is based on PackageAccess.READ OPCPackage
Summary: SXSSFWorkbook.write() fails when the template is based on PackageAccess.READ ...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.14-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-16 21:52 UTC by Yavor
Modified: 2016-09-12 23:12 UTC (History)
0 users



Attachments

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