gpt4 book ai didi

java - Apache POI poi-ooxml :4. 0.0 抛出 org.apache.poi.ooxml.POIXMLException

转载 作者:行者123 更新时间:2023-12-02 10:39:55 28 4
gpt4 key购买 nike

上下文:

尝试使用 Apache POI 的 poi 和 poi-ooxml 4.0.0 版本 jar 打开 XLSX 文件

问题:

程序抛出错误,如下所示。当我使用 4.0.0 版本时,我发现此错误,因为我能够使用 3.17 或更早版本打开 excel 文件。

希望所面临的问题是清楚的,并等待有关如何解决此问题的意见。

注意:找到一些相关查询,但它们与 POI 的早期版本相关 - Link1 Link2

代码:

public static void main(String[] args) {
try {
// Open Excel XLSX file
FileInputStream fis = new FileInputStream(excelFile);
ZipSecureFile.setMinInflateRatio(0);
XSSFWorkbook workBook = new XSSFWorkbook(fis);
System.out.println(workBook);
} catch (Exception e) {
e.printStackTrace();
}
}

Gradle :

compile 'org.apache.poi:poi:4.0.0'
compile 'org.apache.poi:poi-ooxml:4.0.0'
// Tried adding the below jar's as well but dint help
// compile 'org.apache.commons:commons-collections4:4.2'
// compile 'org.apache.poi:poi-ooxml-schemas:4.0.0'
// compile 'org.apache.xmlbeans:xmlbeans:3.0.1'

错误:

org.apache.poi.ooxml.POIXMLException: org/apache/poi/POIXMLTypeLoader
at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:66)
at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:648)
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 main.Test.main(Test.java:32)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
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.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader
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
Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more

最佳答案

我在尝试使用 poi 4.0.1 时遇到了同样的问题。

添加 compile "org.apache.poi:ooxml-schemas:1.4" 为我解决了这个问题

我的所有依赖项:

compile "org.apache.poi:ooxml-schemas:1.4"
compile "org.apache.poi:poi:4.0.1"
compile "org.apache.poi:poi-ooxml:4.0.1"

关于java - Apache POI poi-ooxml :4. 0.0 抛出 org.apache.poi.ooxml.POIXMLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52992755/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com