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

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

问题描述

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

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>

我在使用 jetty 插件运行时遇到以下异常,即使部署在 tomcat 中也是如此.

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

我删除了 xmlbeans 依赖,因为 maven 会自动下载 poi 依赖,还是一样的异常.有什么帮助吗?

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

推荐答案

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

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

编译'org.apache.poi:ooxml-schemas:1.1'

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

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

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