解决poi导出Excel异常org.openxmlformats.schemas.spreadshe

简介: JAVA报表 POI未捕获到 servlet OUTEXCEL 的其中一个服务方法中抛出的异常。抛出的异常:java.lang.NoClassDefFoundError: org.openxmlformats.

JAVA报表

POI未捕获到 servlet OUTEXCEL 的其中一个服务方法中抛出的异常。抛出的异常:java.lang.NoClassDefFoundError: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFileRecoveryPr

at java.lang.J9VMInternals.verifyImpl(Native Method)

at java.lang.J9VMInternals.verify(J9VMInternals.java:59)

at java.lang.J9VMInternals.initialize(J9VMInternals.java:120)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:67)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:521)

at org.apache.xmlbeans.impl.schema.SchemaTypeImpl.createUnattachedNode(SchemaTypeImpl.java:1859)

at org.apache.xmlbeans.impl.schema.SchemaTypeImpl.createTypeStoreUser(SchemaTypeImpl.java:1805)

at org.apache.xmlbeans.impl.store.Xobj.setStableType(Xobj.java:1390)

at org.apache.xmlbeans.impl.store.Cur.setType(Cur.java:2497)

at org.apache.xmlbeans.impl.store.Cur.setType(Cur.java:2482)

at org.apache.xmlbeans.impl.store.Locale.newInstance(Locale.java:630)

at org.apache.xmlbeans.impl.store.Locale.newInstance(Locale.java:606)

at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.newInstance(SchemaTypeLoaderBase.java:198)

 

经过确认,是由于poi使用的poi-ooxml-schemas是ooxml-schemas的精简版,所以在was服务器上导出Excel可能会报错,tomcat下面使用前者是没有问题的,此时需要统一jar包版本为ooxml-schemas.1.1.jar,这个ooxml-schemas有两个版本的jar包,一个是 POI 3.7,之前版本使用的ooxml-schemas-1.0.jar.另一个就是poi3.7以后版本使用的ooxml-schemas-1.1.jar,官网也说了这个问题:http://poi.apache.org/faq.html#faq-N10025,

 

here are two jar files available, as described in the components overview section. The full jar of all of the schemas is ooxml-schemas-1.1.jar, and it is currently around 15mb. The smaller poi-ooxml-schemas jar is only about 4mb. This latter jar file only contains the typically used parts though.

 

Note that for POI 3.5 and 3.6, the full ooxml schemas jar was named ooxml-schemas-1.0.jar. For POI 3.7, the filename was bumped to ooxml-schemas-1.1.jar when generics support was added. You can use ooxml-schemas-1.1.jar with POI 3.5 and 3.6 if you wish, but POI 3.7 won't wokr with ooxml-schemas-1.0.jar (it needs thew newer one).

 

意思很简单,把你的poi需要依赖的jar包给从

1.maven下解决方案如下:

<!--  适合Tomcat 的缩减版ooxml-schemas-3.9 

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml-schemas</artifactId>

<version>3.9</version>

</dependency>

-->

 

换成下面的

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>ooxml-schemas</artifactId>

<version>1.1</version>

</dependency>

 

重启服务,导出excel就ok了。

ps:poi3.9 一共需要如下几个jar包,才能正常工作。

<!-- poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
 
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.9</version>
        </dependency>
 
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
 
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.3.0</version>
        </dependency>
 
        <dependency>
            <groupId>stax</groupId>
            <artifactId>stax-api</artifactId>
            <version>1.0.1</version>
        </dependency>
 
        <!--  适合Tomcat 的缩减版ooxml-schemas-3.9
            <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>3.9</version>
            </dependency>
        -->
 
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>ooxml-schemas</artifactId>
            <version>1.1</version>
        </dependency>
 
        <!-- poi end-->

2.普通的web工程,去下载jar包。

此jar包在maven官网 的 下载地址:http://search.maven.org/#artifactdetails%7Corg.apache.poi%7Cooxml-schemas%7C1.1%7Cjar

目录
相关文章
|
3天前
|
Java
java导出复杂excel
java导出复杂excel
|
2天前
|
Java Apache 索引
POI操作大全(动态合并单元格,为单元格生成一个自定义的数据显示格式,自定义公式计算结果生成,读取excel,word文件在生成图片,word指定位置生成图片)
POI操作大全(动态合并单元格,为单元格生成一个自定义的数据显示格式,自定义公式计算结果生成,读取excel,word文件在生成图片,word指定位置生成图片)
|
2天前
|
开发框架 资源调度 JavaScript
uniapp本地导出表格excel
uniapp本地导出表格excel
|
3天前
|
前端开发 关系型数据库 MySQL
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
【MySQL × SpringBoot 突发奇想】全面实现流程 · 数据库导出Excel表格文件的接口
24 0
|
3天前
|
JavaScript
vue导出excel无法打开问题
vue导出excel无法打开问题
|
3天前
|
easyexcel BI
excel合并列导出文件
excel合并列导出文件
|
3天前
|
easyexcel
【EasyExcel】第二篇:导出excel文件,导出多个sheet工作空间
【EasyExcel】第二篇:导出excel文件,导出多个sheet工作空间
|
3天前
|
SQL 数据库连接 数据库
【SQL Server】2. 将数据导入导出到Excel表格当中
【SQL Server】2. 将数据导入导出到Excel表格当中
50 0
|
3天前
|
NoSQL 关系型数据库 MySQL
多人同时导出 Excel 干崩服务器?怎样实现一个简单排队导出功能!
业务诉求:考虑到数据库数据日渐增多,导出会有全量数据的导出,多人同时导出可以会对服务性能造成影响,导出涉及到mysql查询的io操作,还涉及文件输入、输出流的io操作,所以对服务器的性能会影响的比较大;结合以上原因,对导出操作进行排队; 刚开始拿到这个需求,第一时间想到就是需要维护一个FIFO先进先出的队列,给定队列一个固定size,在队列里面的人进行排队进行数据导出,导出完成后立马出队列,下一个排队的人进行操作;还考虑到异步,可能还需要建个文件导出表,主要记录文件的导出情况,文件的存放地址,用户根据文件列表情况下载导出文件。
多人同时导出 Excel 干崩服务器?怎样实现一个简单排队导出功能!
|
3天前
|
JavaScript 前端开发
【导出Excel】Vue实现导出下载Excel文件(blob文件流)--亲测可用
【导出Excel】Vue实现导出下载Excel文件(blob文件流)--亲测可用
【导出Excel】Vue实现导出下载Excel文件(blob文件流)--亲测可用