alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.09k stars 7.5k forks source link

excel 导出日期格式筛选问题 #3813

Closed of0 closed 3 months ago

of0 commented 4 months ago

异常提示 easyexcel 2.2.6 使用的数据 image

如果您使用过excel的日期排序, 它应该是这样的 image

但是使用easyexcel 导出之后, excel筛选居然是这样的,只有双击单元格后才正常

img

目前多种尝试, 除非双击单元格, 不然导出的excel日期类型筛选都不是想要的, 请问一下这个有好的解决方案么

psxjoy commented 4 months ago

参考 日期数字或者自定义格式转换
Not a bug,change to help wanted tag.

of0 commented 4 months ago

是按照日期格式写的 @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") @ExcelProperty("日期标题") private Date date;

还是导出没有办法按日期筛选

psxjoy commented 4 months ago

能提供一个可以运行的demo吗?

获取 Outlook for iOShttps://aka.ms/o0ukef


发件人: CoderXin @.> 发送时间: Thursday, May 30, 2024 9:45:30 AM 收件人: alibaba/easyexcel @.> 抄送: Black Pan @.>; Comment @.> 主题: Re: [alibaba/easyexcel] excel 导出日期格式筛选问题 (Issue #3813)

是按照日期格式写的 @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") @ExcelProperty("日期标题") private Date date;

还是导出没有办法按日期筛选

― Reply to this email directly, view it on GitHubhttps://github.com/alibaba/easyexcel/issues/3813#issuecomment-2138521822, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACRXFDUVU7BSCOOUQ3MZY5TZE2ADVAVCNFSM6AAAAABIMDDBLSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZYGUZDCOBSGI. You are receiving this because you commented.Message ID: @.***>

of0 commented 4 months ago

其实直接用你们的示例就行。

@Test
public void test5() {

    String fileName = "/Users/zjx/Downloads/converterWrite" + System.currentTimeMillis() + ".xlsx";
    // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭

    List<ConverterData> data = new ArrayList<>();
    data.add(new ConverterData(new Date(1717034452040L)));
    data.add(new ConverterData(new Date(1717854452040L)));
    data.add(new ConverterData(new Date(1717012452040L)));
    data.add(new ConverterData(new Date(1717036652040L)));
    EasyExcel.write(fileName, ConverterData.class).sheet("模板").doWrite(data);

}

@Data @EqualsAndHashCode class ConverterData {

/**
 * 我想写到excel 用年月日的格式
 */
@DateTimeFormat("yyyy/MM/dd")
@ExcelProperty("日期标题")
private Date date;

public ConverterData(Date date) {
    this.date = date;
}

}

of0 commented 4 months ago

这段代码运行后生成的 excel 点筛选就是这个效果:

image

双击单元格以后才能按照日期筛选:

image
psxjoy commented 4 months ago

用官方demo,分别跑了 mac、win系统下的 wps 和 excel ,打开均能正常筛选。 怀疑是开发环境问题。建议换其他机器测试一下。

of0 commented 4 months ago

是版本问题吗?我用的是easyexcel 2.2.6

psxjoy commented 4 months ago

建议升到最新版,或者 3.1.0+ 版本。 按照升级路径,2.2.x版本已经弃用了

不推荐项目新引入此版本,除非是 jdk6,否则不推荐使用,除非超级严重bug,否则不再更新

of0 commented 4 months ago

确认了,是版本问题,升级到 3.3.1版本好了。 谢谢!

psxjoy commented 3 months ago

It is not a bug, please change it to the help wanted tag. @zhuangjiaju

psxjoy commented 3 months ago

This issue has been completed, I will close this issue.