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

相关推荐
开开心心就好7 小时前
轻松鼠标连, 自定义区域模仿人手点击
人工智能·windows·物联网·计算机视觉·计算机外设·ocr·excel
AI_567810 小时前
ableau可视化进阶:颜色与交互设计让数据会说话
数据库·云原生·excel
城数派10 小时前
2001-2024年我国乡镇级的逐年植被净初级生产力(NPP)数据(Shp/Excel格式)
大数据·数据分析·excel
开开心心_Every1 天前
局域网大文件传输,设密码双向共享易用工具
运维·服务器·网络·游戏·pdf·电脑·excel
Data-Miner1 天前
本地化数据分析 agent,让 Excel 数据分析零门槛高效化
数据挖掘·数据分析·excel
盘古工具3 天前
告别重复数据:Excel禁止重复输入的两种方法
windows·excel
jiayong234 天前
Excel 核心功能详解
信息可视化·excel
未来之窗软件服务4 天前
万象EXCEL(二十五)租赁设备管理系统,设备租赁—东方仙盟
大数据·excel·仙盟创梦ide·东方仙盟·万象excel
骑猪撞地球QAQ4 天前
Java在导出excel时中添加图片导出
java·开发语言·excel
计算机软件程序设计4 天前
Python读取Excel/CSV到MySQL
python·mysql·excel