Bug 56675 - Cannot create new XSSFWorkbook from an OPCPackage that opened an Excel 2013 file with PackageAccess.READ
Summary: Cannot create new XSSFWorkbook from an OPCPackage that opened an Excel 2013 f...
Status: RESOLVED DUPLICATE of bug 57482
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (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-06-26 21:12 UTC by Nick Odaemus
Modified: 2015-01-22 15:02 UTC (History)
1 user (show)



Attachments
A blank workbook created in Excel 2013 (7.46 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2014-06-27 18:00 UTC, Nick Odaemus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Odaemus 2014-06-26 21:12:17 UTC
I've attempted to open files created in Excel 2013 as an XSSFWorkbook via an OPCPackage with PackageAccess.READ, but it throws a POIXMLException with the following stack (I have added my code after):

Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidOperationException: Operation not allowed, document open in read only mode!
  at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:393)
  at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:353)
  at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:288)
  at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
  at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:200)
  at workbook.io.WorkbookReaderTest.<init>(WorkbookReaderTest.java:19)
  at workbook.io.WorkbookReaderTest.main(WorkbookReaderTest.java:25)
Caused by: 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:507)
  at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:765)
  at org.apache.poi.openxml4j.opc.OPCPackage.createPart(OPCPackage.java:741)
  at org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:373)
  ... 6 more


Here's my code:


public final class WorkbookReaderTest {

  public WorkbookReaderTest(File inputFile) throws InvalidFormatException, IOException {
    OPCPackage pkg = OPCPackage.open(inputFile, PackageAccess.READ);
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
  }

  public static void main(String[] args) throws InvalidFormatException, IOException {
    new WorkbookReaderTest(new File("C:\\path\\blank workbook.xlsx"));
  }
}

It seems that XLSX files created in Excel 2013 are the problem. XLSX files created in 2010 and then modified in 2013 seem to pose no problem, provided that at least 2 sheets remain from the original; when cut down to only 1 sheet from the original, I get the same exception, even if the 1 original sheet has new accompanying sheets in the same workbook.
Comment 1 Nick Burch 2014-06-26 22:18:48 UTC
Any chance you could upload a sample file that shows the problem, along with a short junit unit test which triggers the exception with it?
Comment 2 Nick Odaemus 2014-06-27 18:00:09 UTC
Created attachment 31757 [details]
A blank workbook created in Excel 2013

This is one of the workbooks I've used to test the issue.

Unfortunately, I have no skill with JUnit.
Comment 3 Dominik Stadler 2015-01-22 15:02:34 UTC
Should be fixed in trunk via bug 57482, checked in with r1653825.

*** This bug has been marked as a duplicate of bug 57482 ***