确定,自身已解决java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Cell.getCellType()情况。
问题出现分析:
公司本身老项目 poi依赖如下:修改依赖版本是不可能的 这辈子都不可能了,
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
解决:在不修改poi版本的前提下,只能让easyExcel想poi进行融合,导入2.1.6版本。借鉴的博客。
easyExcel的maven依赖(备忘)_不开窍的博客-CSDN博客_easyexcel依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
引入后,解决找不到方法的问题。
但是因为2.1.6的版本 (貌似有点低),无法兼容 LocaldateTime类型,如果项目导出excel需要用到LocalDateTime字段 需要创建一个配置类。原文来自下面的博主:
Can not find ‘Converter‘ support class LocalDateTime_爱喝椰汁的木木的博客-CSDN博客
/**
* 自定义LocalDateStringConverter
* 用于解决使用easyexcel导出表格时候,默认不支持LocalDateTime日期格式
*
* 在需要的属性上添加注解 @ExcelProperty(value = "入职时间", converter = LocalDateStringConverter.class)
*/
@Component
public class LocalDateStringConverter implements Converter<LocalDateTime> {
@Override
public Class supportJavaTypeKey() {
return LocalDateTime.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
@Override
public CellData convertToExcelData(LocalDateTime localDateTime, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String format = formatter.format(localDateTime);
return new CellData(format);
}
}