使用easyPOI時碰到的幾個問題(記錄一下)

前言

前面咱們說了如何使用easyPOI,詳情請參考全網最全最簡單使用easypoi導入導出Excel的操做手冊,今天我來記錄下在使用easyPOI時碰到的幾個問題,原本覺得上傳下載功能使用EasyPOI以後挺簡單的,結果翻車了,一個上傳和下載就由於版本的問題搞了老半天。真的是很愁人呀。下面就是我係統的初始環境。java

環境

<!-- springboot -->
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>
	 <!-- springboot -->
	 
	<!--easypoi-->
	 <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-spring-boot-starter</artifactId>
            <version>4.0.0</version>
        </dependency>
 <!--easypoi-->
 
 <!--commons-collections4-->
 <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.0</version>
        </dependency>
	 <!--commons-collections4-->

原本覺得一件很是簡單的事情,結果一連碰到了三個問題,啪啪打臉呀。問題分別以下:spring

問題1(ArrayListValuedHashMap找不到)

提示ArrayListValuedHashMap找不到的問題,報錯以下圖所示:
在這裏插入圖片描述
這個問題主要就是由於commons-collections4的版本是4.0,版本比較低,升級到4.1後就能夠了。,升級後的依賴以下:

apache

<dependency>
           <groupId>org.apache.commons</groupId>
           <artifactId>commons-collections4</artifactId>
           <version>4.1</version>
       </dependency>

解決第一個問題以後,緊接着我就碰到第二個問題。上傳的時候文件的時候一樣仍是提示某某類找不到的問題。這有點讓人揪心。springboot

問題2(CellType類找不到)

第二個問題以下圖所示:提示CellType類找不到,真的就很奇怪了,這個類明明能夠搜索的到,爲啥系統就提示找不到呢?
在這裏插入圖片描述
一番百度以後仍是無果,莫得辦法,我只有嘗試着將easypoi-spring-boot-starter依賴的版本從4.0.0降到3.3.0。版本換成3.3.0以後,上傳文件就能夠了,真的是太神奇了。

spring-boot

<dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-spring-boot-starter</artifactId>
            <version>3.3.0</version>
        </dependency>

問題3(CellStyle.setAlignment)

搞定上傳文件的功能以後,我很開行,緊接着就去試試下載文件的功能了。哎,老天捉弄我呀,以前一直好好的的下載功能,就在我將easypoi-spring-boot-starter依賴的版本從4.0.0降到3.3.0以後,就不行了。報錯以下:工具

Caused by: java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.CellStyle.setAlignment(S)V
	at cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl.stringNoneStyle(ExcelExportStylerDefaultImpl.java:69) ~[easypoi-base-3.3.0.jar:?]
	at com.nuonuo.juhe.common.util.excel.ExcelStyleUtil.stringNoneStyle(ExcelStyleUtil.java:42) ~[classes/:?]
	at cn.afterturn.easypoi.excel.export.styler.AbstractExcelExportStyler.createStyles(AbstractExcelExportStyler.java:44) ~[easypoi-base-3.3.0.jar:?]
	at cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl.<init>(ExcelExportStylerDefaultImpl.java:31) ~[easypoi-base-3.3.0.jar:?]
	at com.nuonuo.juhe.common.util.excel.ExcelStyleUtil.<init>(ExcelStyleUtil.java:16) ~[classes/:?]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_181]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_181]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_181]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_181]
	at cn.afterturn.easypoi.excel.export.ExcelExportService.insertDataToSheet(ExcelExportService.java:225) ~[easypoi-base-3.3.0.jar:?]

哎,又是這個CellStyle類的問題,真的很愁人呀。沒有辦法,只得繼續去處理。又是一番百度。從網上獲得了一個答案,說的是須要將poi-ooxml的版本從3.17降到3.15。可是,我找了一圈我也沒找到項目中有直接引入poi-ooxml這個依賴。找了半天發現項目中一個工具類中引入了poi-ooxml依賴,版本號是3.17。(PS: 找依賴的方法是:在Maven Projects中選中項目,右鍵Show Dependencies)而easypoi-spring-boot-starter依賴已經引入的poi-ooxml依賴的版本是3.15。 這裏就出現了版本衝突。處理方式就是將工具類中的那個poi-ooxml依賴去除掉。spa

<exclusions>
                <exclusion>
                    <groupId>org.apache.poi</groupId>
                    <artifactId>poi-ooxml</artifactId>
                </exclusion>
            </exclusions>

這三個問題處理好以後,上傳文件和下載文件就處理好了。.net

相關文章
相關標籤/搜索