原因:easyexcel不支持此类型。
不支持的类型Date
这里我是Date类型:
报错:Can not find 'Converter' support class Timestamp.
解决:
第一步:实现Converter类重写方法
public class TimestampStringConverter implements Converter<Timestamp> {
@Override
public Class<?> supportJavaTypeKey() {
return Timestamp.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public WriteCellData<?> convertToExcelData(Timestamp value, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
WriteCellData cellData = new WriteCellData();
String cellValue;
if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) {
cellValue = DateUtils.format(value.toLocalDateTime(), null, globalConfiguration.getLocale());
} else {
cellValue = DateUtils.format(value.toLocalDateTime(), contentProperty.getDateTimeFormatProperty().getFormat(),
globalConfiguration.getLocale());
}
cellData.setType(CellDataTypeEnum.STRING);
cellData.setStringValue(cellValue);
cellData.setData(cellValue);
return cellData;
}
}
第二步:写出时调用此类
.registerConverter(new 刚才写的转换类())
EasyExcel.write(response.getOutputStream()).head(headsFromVO(customizeHeads)).registerConverter(new TimestampStringConverter()).sheet(needExportHeadDTO.getSheetName()).doWrite(data);
解决: