读取xlsx文件时出现apache POIexception

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

 org.apache.poi poi-ooxml 3.8   org.apache.xmlbeans xmlbeans 2.5.0  

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

 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.(StylesTable.java:92) ... 186 more 

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

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

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

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

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


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

当我尝试其他人时,它不起作用:

3.10:maven central不知道

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

结论POI 3.9有效!!!!

我尝试使用带有Grails的poi 3.103.12 beta并获得此错误。

下载并包含http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/poi/ooxml-schemas/1.0/oox​​ml-schemas-1.0.jar后 ,错误消失了。

我使用3.7,但你尝试添加

   org.apache.poi poi-ooxml-schemas 3.8