Hello, expert,

I got the following stack trace when creaing XSSFWorkbook with
PackageAccess.READ:

Unstructured_Data_0,0: 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:370)

    at
org.apache.poi.POIXMLDocumentPart.createRelationship(POIXMLDocumentPart.java:330)

    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:274)

    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
    at
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:186)
   ...

My code is like below.
   Workbook workbook = new
XSSFWorkbook(OPCPackage.open(file.getAbsolutePath(), PackageAccess.READ));

It usually works fine; however the above exception occurs when reading some
Excel (xlsx) files. I found similar bug reports such as 55948 and 56675,
but unfortunately they are not fixed yet.

As a result of my investigation, I recognized this issue occurs when
reading an xlsx file that contains only numeric data. In this case there is
no shared string table, POI tries to create a new part named
"/xl/sharedStrings.xml" and then throws the exception.
It seems a POI logic issue. It should be allowed even if PackageAccess.READ
is specified.

Is there any workaround?

Regards,
Isao

Reply via email to