格式化
本章节将介绍写入数据时的数据格式化。
自定义格式写入
概述
支持日期、数字或其他自定义格式,通过注解实现。
POJO 类
@Getter
@Setter
@EqualsAndHashCode
public class ConverterData {
@ExcelProperty(value = "字符串标题", converter = CustomStringStringConverter.class)
private String string;
@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
@ExcelProperty("日期标题")
private Date date;
@NumberFormat("#.##%")
@ExcelProperty("数字标题")
private Double doubleData;
}
代码示例
@Test
public void converterWrite() {
String fileName = "converterWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName, ConverterData.class)
.sheet()
.doWrite(data());
}
结果
| A | B | C | |
| 1 | 字符串标题 | 日期标题 | 数字标题 |
| 2 | 自定义:字符串0 | 2024年12月03日20时50分23秒 | 56.% |
| 3 | 自定义:字符串1 | 2024年12月03日20时50分23秒 | 56.% |
| 4 | 自定义:字符串2 | 2024年12月03日20时50分23秒 | 56.% |
| ⋮ | … | … | … |
| 11 | 自定义:字符串9 | 2024年12月03日20时50分23秒 | 56.% |