使用jxlsReader读取excel报错
JxlsReader.read(INTERPRETATION_DATA_IMPORT_XML, excel.getAbsolutePath(), beans);
报错为:找不到CellType方法,但是在/apache/poi/ss/usermodel/CellType中确实又存在
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Cell.getCellType()Lorg/apache/poi/ss/usermodel/CellType;
先查看项目引入的依赖:
<jxls.version>2.4.5</jxls.version>
<jxls-poi.version>1.0.15</jxls-poi.version>
<jxls-reader.version>2.0.3</jxls-reader.version>
<!-- https://mvnrepository.com/artifact/org.jxls/jxls -->
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>${jxls.version}</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>${jxls-poi.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jxls/jxls-reader -->
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-reader</artifactId>
<version>${jxls-reader.version}</version>
</dependency>
在网上找了一圈都说是poi版本太低了(jxls-poi1.0.15引入的poi版本为3.17),但是在这个项目并没有引入poi,意识到 jxls-poi应该已经包含了相应的poi版本,于是想将poi版本升级到4.0,在官网(http://jxls.sourceforge.net/changes.html)找到的日志如下:
重新设置依赖版本
<jxls.version>2.4.7</jxls.version>
<jxls-poi.version>1.0.16</jxls-poi.version>
<jxls-reader.version>2.0.5</jxls-reader.version>
<!-- https://mvnrepository.com/artifact/org.jxls/jxls -->
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
<version>${jxls.version}</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
<version>${jxls-poi.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jxls/jxls-reader -->
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-reader</artifactId>
<version>${jxls-reader.version}</version>
</dependency>
完美搞定!
注意:因为jxlsReader是读取xml模板,所以在升级jxlsReader的同时将xmlbeans也升级
<xmlbeans.version>3.1.0</xmlbeans.version>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>${xmlbeans.version}</version>
</dependency>
|