Apache POI解析错误
我知道这个问题经常被问到,但是找不到合适的解决方案。使用时
XWPFDocument xdoc = new XWPFDocument(srcFile);
要么
XSSFWorkbook workbook = new XSSFWorkbook(srcFile);
我总是会遇到以下错误:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V from class org.apache.poi.openxml4j.opc.PackageRelationshipCollection at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:163)
at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.<init>(PackageRelationshipCollection.java:131)
at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:109)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:80)
at org.apache.poi.openxml4j.opc.PackagePart.<init>(PackagePart.java:125)
at org.apache.poi.openxml4j.opc.ZipPackagePart.<init>(ZipPackagePart.java:78)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:243)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:266)
人们建议打开PackageRelationshipCollection
并重试。但这并没有太大帮助。
我也有装的罐子:
<dependency> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.13</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.12</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.11</version>
<type>jar</type>
</dependency>
回答:
从Apache POI常见问题解答:
否。不支持此功能。
所有使用中的POI罐子必须来自同一版本。不支持诸如poi-3.11.jar和poi-
ooxml-3.9.jar之类的组合,它们将无法以不可预测的方式工作。
您的pom依赖于3.11、3.12和3.13中的Apache POI
jar,不支持FAQ所述
您需要将所有这些更改为3.13,然后它将起作用
我建议类似的东西:
<properties> <poi.version>3.13</poi.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<!-- etc as needed -->
这样,您可以确保所有POI罐都来自同一版本!
以上是 Apache POI解析错误 的全部内容, 来源链接: utcz.com/qa/399392.html