读取xlsx文件中的apache POI异常。

时间:2021-07-28 20:21:07

I'm using apache POI for reading xlsx files by adding below dependencies

我使用apache POI通过添加以下依赖项来读取xlsx文件。

<dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.8</version>
        </dependency>

<dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.5.0</version>
        </dependency>

I'm getting following exception while running with jetty plugin even if deployed in tomcat.

在运行jetty插件时,即使部署在tomcat中,我也会遇到异常。

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
    at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
    at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
......

Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...........
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121)
    at org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:92)
    ... 186 more

I removed the xmlbeans dependency as the maven will automatically download poi dependencies , still the same exception.Any help?

我删除了xmlbeans依赖项,因为maven将自动下载poi依赖项,仍然是相同的异常。任何帮助吗?

4 个解决方案

#1


15  

I used poi with version 3.12. The following dependency is also required:

我用的是版本3.12的poi。还需要以下依赖项:

compile 'org.apache.poi:ooxml-schemas:1.1'

编译“org.apache.poi:ooxml-schemas:1.1”

see also http://poi.apache.org/faq.html#faq-N10025

参见http://poi.apache.org/faq.html faq-N10025

#2


4  

I have made it run for these dependencies:

我已经让它运行这些依赖项:

     def poiVersion='3.9'
     compile 'org.apache.poi:poi:'+poiVersion
     compile 'org.apache.poi:poi-ooxml:'+poiVersion
     compile 'org.apache.poi:poi-ooxml-schemas:'+poiVersion

When I try for others it does not work:

当我为别人努力时,它就不起作用了:

3.10 : is not known to maven central

3.10:maven中心不知道。

3.11 : fails, with exact the error in this case !!!

3.11:失败,在这种情况下有准确的错误!!!

Conclusion POI 3.9 works !!!!

结论POI 3.9工作!!!!

#3


4  

I tried using poi 3.10, 3.11 and 3.12 beta with Grails and get this error as well.

我尝试使用了poi 3.10、3.11和3.12 beta和Grails,并得到了这个错误。

After downloading and including http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/ooxml-schemas-1.0.jar the error is gone.

下载后,包括http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/ooxml-schemas-1.0.jar,错误就消失了。

#4


0  

I use 3.7 but have you try adding

我用3.7,但你试着加。

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.8</version>
    </dependency>

#1


15  

I used poi with version 3.12. The following dependency is also required:

我用的是版本3.12的poi。还需要以下依赖项:

compile 'org.apache.poi:ooxml-schemas:1.1'

编译“org.apache.poi:ooxml-schemas:1.1”

see also http://poi.apache.org/faq.html#faq-N10025

参见http://poi.apache.org/faq.html faq-N10025

#2


4  

I have made it run for these dependencies:

我已经让它运行这些依赖项:

     def poiVersion='3.9'
     compile 'org.apache.poi:poi:'+poiVersion
     compile 'org.apache.poi:poi-ooxml:'+poiVersion
     compile 'org.apache.poi:poi-ooxml-schemas:'+poiVersion

When I try for others it does not work:

当我为别人努力时,它就不起作用了:

3.10 : is not known to maven central

3.10:maven中心不知道。

3.11 : fails, with exact the error in this case !!!

3.11:失败,在这种情况下有准确的错误!!!

Conclusion POI 3.9 works !!!!

结论POI 3.9工作!!!!

#3


4  

I tried using poi 3.10, 3.11 and 3.12 beta with Grails and get this error as well.

我尝试使用了poi 3.10、3.11和3.12 beta和Grails,并得到了这个错误。

After downloading and including http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/ooxml-schemas-1.0.jar the error is gone.

下载后,包括http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/ooxml-schemas-1.0.jar,错误就消失了。

#4


0  

I use 3.7 but have you try adding

我用3.7,但你试着加。

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.8</version>
    </dependency>