Joey
Joey

Reputation: 697

Apache POI XmlException for theme (http://purl.oclc.org/ooxml/drawingml)

Currently, I'm using Apache POI for reading an excel file(.xlsx) but encountering an exception during instantiation of XSSFWorkbook when passing the data stream. Below is the exception encountered.

Apache Poi version: 4.0.1

Exception in thread "main" org.apache.poi.ooxml.POIXMLException: error: The document is not a theme@http://schemas.openxmlformats.org/drawingml/2006/main: document element namespace mismatch expected "http://schemas.openxmlformats.org/drawingml/2006/main" got "http://purl.oclc.org/ooxml/drawingml/main"
    at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:66)
    at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:657)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:307)
    at com.wl.dni.excel.parser.Test.main(Test.java:47)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)
    at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63)
    ... 5 more
Caused by: java.io.IOException: error: The document is not a theme@http://schemas.openxmlformats.org/drawingml/2006/main: document element namespace mismatch expected "http://schemas.openxmlformats.org/drawingml/2006/main" got "http://purl.oclc.org/ooxml/drawingml/main"
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:88)
    ... 11 more
Caused by: org.apache.xmlbeans.XmlException: error: The document is not a theme@http://schemas.openxmlformats.org/drawingml/2006/main: document element namespace mismatch expected "http://schemas.openxmlformats.org/drawingml/2006/main" got "http://purl.oclc.org/ooxml/drawingml/main"
    at org.apache.xmlbeans.impl.store.Locale.verifyDocumentType(Locale.java:454)
    at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:359)
    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1275)
    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
    at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
    at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)
    ... 11 more

Any idea how to fix this kind of issue or library can be use. Thanks.

Upvotes: 0

Views: 1061

Answers (1)

PJ Fanning
PJ Fanning

Reputation: 1046

Apache POI does not support xlsx files saved with Strict OOXML format (which uses the http://purl.oclc.org/ooxml/drawingml namespace).

Try to save the file using standard (transitional) OOXML format.

https://github.com/pjfanning/ooxml-strict-converter might help if you need to convert the file yourself.

Upvotes: 2

Related Questions