Skip to main content

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 = "字符串标题", converter = CustomStringStringConverter.class)
private String string;

@DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒")
@ExcelProperty("日期标题")
private Date date;

@NumberFormat("#.##%")
@ExcelProperty("数字标题")
private Double doubleData;
}

Code Example

@Test
public void converterWrite() {
String fileName = "converterWrite" + System.currentTimeMillis() + ".xlsx";
FastExcel.write(fileName, ConverterData.class)
.sheet()
.doWrite(data());
}

Result

img