解決poi導出Excel異常org.openxmlformats.schemas.spreadshe


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM