java - 主题的 Apache POI XmlException (http ://purl. oclc.org/ooxml/drawingml)

标签 java apache-poi xssf

目前,我正在使用 Apache POI 读取 Excel 文件(.xlsx),但在传递数据流时实例化 XSSFWorkbook 期间遇到异常。下面是遇到的异常。

Apache Poi 版本: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

可以使用任何解决此类问题或库的想法。谢谢。

最佳答案

Apache POI 不支持以严格 OOXML 格式(使用 http://purl.oclc.org/ooxml/drawingml 命名空间)保存的 xlsx 文件。

尝试使用标准(过渡)OOXML 格式保存文件。

https://github.com/pjfanning/ooxml-strict-converter如果您需要自己转换文件可能会有所帮助。

关于java - 主题的 Apache POI XmlException (http ://purl. oclc.org/ooxml/drawingml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55536616/

相关文章:

java - 使用 MessageDigest SHA-256 的 POI XSSF/XLSX 散列不确定性

apache-poi - Apache POI - XSSF : Row. getCell()

java - XSSFWorkbook 错误 - MoSTLy 缺少一些 Jar 或依赖项

javascript - 如何使用 Javascript 的 Java 驱动程序在 MongoDB 中插入 created_timestamp

java - Jackson配置自己的json

java - Apache Poi 单元数据重复

java - 使用 Apache POI 的基本 Excel 货币格式

java - 声明 float ,为什么默认类型为 double?

java - 使用java重新启动远程计算机

java - 不使用InputStream更新Java Apache POI中的现有Excel文件