[alibaba/easyexcel]写excel的时候format不起作用吗?

2024-06-20 962 views
0

@ExcelProperty(value = "创建时间" ,index = 2, format = "yyyy-MM-dd HH:mm:ss")
private Date createDate;

excel显示: Wed Sep 26 21:20:32 CST 2018

回答

5

同,写的时候 format 好像并未调用

5

要重写set方法,这样就会起作用 eg: @ExcelProperty(index = 12,value = "绑定时间",format = "yyyy-MM-dd HH:mm:ss") private String bindTime;

public void setBindTime(Date bindTime) {
    this.bindTime = DateUtils.formatSecond(bindTime);
}
2

问题是,写的时候 format 不生效 想达成的结果是 字段本身是 Date 类型,通过 format 导出成 yyyy-MM-dd HH:mm:ss 这种格式 而现状是:Date 类型 导出的时候好像并未调用 format ,实际导出结果为 Wed Sep 26 21:20:32 CST 2018 这种形式

3

你要定义为string类型 通过 format 导出成 yyyy-MM-dd HH:mm:ss 这种格式

7

那只能说是不支持类型自动转换了,不知道以后会不会支持

0

同上,我也有这样的需求,希望能支持

6

ExcelBuilderImpl.addOneRowOfDataToExcel 我加了这些代码

Class<?> type = excelHeadProperty.getField().getType(); if (Date.class.equals(type)){ ExcelProperty excelProperty = excelHeadProperty.getField().getAnnotation(ExcelProperty.class); ExcelColumnNum excelColumnNum = excelHeadProperty.getField().getAnnotation(ExcelColumnNum.class); String format = null; if (excelProperty != null){ format = excelProperty.format(); }else if (excelColumnNum != null){ format = excelColumnNum.format(); }else { format = "yyyy-MM-dd HH:mm:ss"; } Date nestedProperty = (Date)BeanUtilsBean.getInstance().getPropertyUtils().getNestedProperty(oneRowData, excelHeadProperty.getField().getName()); cellValue = TypeUtil.fromatDateToString(nestedProperty,format);

0

重写set方法就行了 不用那么麻烦

2

image 可以的呀。老哥

7

有新版本了么,还是说我们的姿势不正确

4

版本更新了

0

1.1.0版本可以了。