Formatting
This chapter introduces data formatting when writing data.
Custom Format Writing
Overview
Supports date, number, or other custom formats through annotations.
POJO Class
@Getter
@Setter
@EqualsAndHashCode
public class ConverterData {
@ExcelProperty(value = "String Title", converter = CustomStringStringConverter.class)
private String string;
@DateTimeFormat("yyyy/MM/dd HH:mm:ss")
@ExcelProperty("Date Title")
private Date date;
@NumberFormat("#.##%")
@ExcelProperty("Number Title")
private Double doubleData;
}
Code Example
@Test
public void converterWrite() {
String fileName = "converterWrite" + System.currentTimeMillis() + ".xlsx";
FesodSheet.write(fileName, ConverterData.class)
.sheet()
.doWrite(data());
}
Result
| A | B | C | |
| 1 | String Title | Date Title | Number Title |
| 2 | Custom: String0 | 2024/12/03 20:50:23 | 56.% |
| 3 | Custom: String1 | 2024/12/03 20:50:23 | 56.% |
| 4 | Custom: String2 | 2024/12/03 20:50:23 | 56.% |
| ⋮ | … | … | … |
| 11 | Custom: String9 | 2024/12/03 20:50:23 | 56.% |