Apache的POI例外阅读XLSX文件(apache POI exception in readi

2019-06-24 00:09发布

我使用的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>

我越来越有码头插件运行,即使部署在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

我删除XMLBeans的依赖作为Maven会自动下载POI的依赖,还是一样exception.Any帮助?

Answer 1:

我用POI与3.12版本。 还需要以下依赖性:

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

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



Answer 2:

我已运行这些依赖关系:


     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

当我尝试对其他人而言,不工作:

3.10:不知道到Maven中央

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

结论POI 3.9作品!!!!



Answer 3:

我试着用poi 3.103.113.12 beta与Grails和得到这个错误也是如此。

下载和加入后http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/oox​​ml-schemas-1.0.jar的错误消失。



Answer 4:

我用3.7,但有你尝试添加

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


文章来源: apache POI exception in reading xlsx files