apache POI异常读取xlsx文件 [英] apache POI exception in reading xlsx files

查看:545
本文介绍了apache POI异常读取xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用apache POI阅读 xlsx 文件,添加以下依赖关系

 依赖性> 
< 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,我也可以使用jetty插件运行时遇到以下异常。

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

导致:java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...........
引起的:java.lang.NoClassDefFoundError:无法初始化类org.openxmlformats .schemas.spreadsheetml.x2006.main.StyleSheetDocument
在org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument $ Factory.pars e(未知来源)
在org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:121)
在org.apache.poi.xssf.model.StylesTable。< init> ;(StylesTable.java:92)
...更多

我删除了xmlbeans依赖关系,因为maven会自动下载poi依赖,仍然是一样的异常。任何帮助?

解决方案

我用poi与3.12版。还需要以下依赖关系:



compile'org.apache.poi:ooxml-schemas:1.1' / p>

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


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

<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.

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?

解决方案

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

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

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

这篇关于apache POI异常读取xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆