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

相关推荐
Non-existent98713 天前
WPS批量清理单元格空白字符的4种方法-异常数字格式处理-实战
excel·wps
Channing Lewis13 天前
PHP 解析 Excel 的那些坑:一次“行号错位”引发的数据丢失
开发语言·php·excel
jarreyer13 天前
【数据分析绘图】excel绘图和bi工具区别
数据挖掘·数据分析·excel
chatexcel14 天前
ChatExcel Max使用教程:图片、PDF、网页与复杂Excel的一站式数据分析
数据分析·pdf·excel
cngkqy14 天前
excel从某一列中用match筛选匹配的数据
excel
qq_5469372714 天前
Excel批量转PDF_Word_图片,支持自动合并报表,效率翻倍。
pdf·word·excel
ai_coder_ai14 天前
在自动化脚本中操作excel文件
运维·自动化·excel
三千花灯14 天前
【Playwright】 自动化测试之参数化登录(Excel/CSV 数据源)
人工智能·机器学习·excel
罗政14 天前
AI工作流实现Excel全自动化(支持SQL)-案例:医院门诊排班表
人工智能·自动化·excel
小妖66614 天前
excel 怎么在单元格内容自动加上一段文字不能用公式
excel·vba