写一个类
![](https://img-blog.csdnimg.cn/img_convert/de2ecb7d8a13fef8be395fb77a12fbde.png)
public class LocalDateConverter implements Converter<LocalDateTime> {
@Override
public Class supportJavaTypeKey() {
return LocalDateTime.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public WriteCellData<?> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
LocalDate localDate = value.toLocalDate();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return new WriteCellData<>(localDate.format(dateTimeFormatter));
}
}
在导出的实体类,有时分秒问题的属性上使用该类的反射
![](https://img-blog.csdnimg.cn/img_convert/1b158662b9d74ced1e59736cb02a609d.png)
宽度调整
![](https://img-blog.csdnimg.cn/img_convert/880c80f8a2f3fe3c2232b73919f218b9.png)