easyexcel和poi同时存在版本问题,使用easyexcel导出excel设置日期格式

这两天在使用easyexcel导出excel的时候日期格式全都是字符串导致导出的excel列无法筛选

后来调整了一下终于弄好了,看一下最终效果

这里涉及到easyexcel和poi版本冲突的问题,一直没搞定,最后狠下心来把所有的都升级到了最新版,然后把程序里的报错都处理了一遍,神奇的是最新版的没出问题,可以导出日期格式,参考了很多博客,记录一下。

最终要调整的地方有三个,一个是poi的版本,一个是easyexcel的版本,另一个是commons-io的版本

xml 复制代码
<commons-io.version>2.18.0</commons-io.version>
<poi.version>5.4.0</poi.version>
<easy-excel.version>4.0.3</easy-excel.version>

<dependency>
	 <groupId>commons-io</groupId>
	 <artifactId>commons-io</artifactId>
	 <version>${commons-io.version}</version>
</dependency>
<dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi</artifactId>
     <version>${poi.version}</version>
 </dependency>
 <dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi-ooxml</artifactId>
     <version>${poi.version}</version>
 </dependency>
 <dependency>
     <groupId>com.alibaba</groupId>
     <artifactId>easyexcel</artifactId>
     <version>${easy-excel.version}</version>
 </dependency>

注意事项

  1. poi的版本对commons-io的版本有要求

https://blog.csdn.net/weixin_48524970/article/details/134379243
https://poi.apache.org/changes.html#5.4.0

  1. 日期格式使用 @ContentStyle(dataFormat = 14)

https://blog.csdn.net/tanghuan0827/article/details/126180146

  1. 日期格式不要进行Converter转换,否则都是字符串

下面是我的实体类的字段

java 复制代码
   @ContentStyle(dataFormat = 14)
   @ExcelProperty(value = {"购入日期"}, index = 9)
   private Date buyDate;
   
   @ContentStyle(dataFormat = 14)
   @ExcelProperty(value = {"报废日期"}, index = 10)
   private LocalDate scrapDate;
   

这种Date和LocalDate导出的数据都是日期格式,关键的设置是@ContentStyle(dataFormat = 14)

参考文献

https://blog.csdn.net/tanghuan0827/article/details/126180146
https://blog.csdn.net/weixin_48524970/article/details/134379243
https://poi.apache.org/changes.html#5.4.0

相关推荐
观远数据13 小时前
Excel继续用、自研BI、替换BI:产品VP拆解三条路线的隐性成本与能力边界
大数据·人工智能·excel
用户298698530141 天前
Excel 转 PDF 免费在线工具,格式完美保留
人工智能·c#·excel
开开心心就好1 天前
文件查重软件批量删除重复文件释放空间
java·开发语言·随机森林·ocr·excel·音视频·最小二乘法
开开心心就好2 天前
文件批量重命名工具简单好用支持规则改名
java·开发语言·b树·ocr·excel·音视频·kmeans
破z晓2 天前
javascript 导出excel表
开发语言·javascript·excel
Am-Chestnuts2 天前
豆包多轮回答中的表格导出 Excel:编号、日期与长数字检查
excel
hPw0eKIqD3 天前
使用二次封装的Excel COM 组件操作Excel\WPS ET中的区域、行和列
excel·wps
冰心孤城3 天前
Excel: xls与xlsx格式转换排坑指南
java·前端·excel
金豆呀3 天前
WPS批量提取Word文档内容生成固定格式Excel表格
word·excel·wps
Access开发易登软件3 天前
Access 怎么做前后端分离?用 Web API 读写 SQL Server
前端·数据库·人工智能·microsoft·excel·access