9
触发Bug的代码
// 字段 省略setter getter
@ExcelProperty(value = "性别", converter = GenderEnumExcelConverter.class)
private GenderEnum gender;
// 转换器
public class GenderEnumExcelConverter implements Converter<GenderEnum> {
@Override
public Class supportJavaTypeKey() {
return GenderEnum.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public GenderEnum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
for (GenderEnum value : GenderEnum.values()) {
if (Objects.equals(value.getCnName(), cellData.getStringValue())) return value;
}
return null;
}
@Override
public CellData convertToExcelData(GenderEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return new CellData(value.getCnName());
}
}
com.alibaba.excel.exception.ExcelDataConvertException: Can not find 'Converter' support class GenderEnum.
at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.doConvert(AbstractExcelWriteExecutor.java:111) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.convert(AbstractExcelWriteExecutor.java:96) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.executor.AbstractExcelWriteExecutor.converterAndSet(AbstractExcelWriteExecutor.java:41) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addJavaObjectToExcel(ExcelWriteAddExecutor.java:164) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.addOneRowOfDataToExcel(ExcelWriteAddExecutor.java:72) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.executor.ExcelWriteAddExecutor.add(ExcelWriteAddExecutor.java:56) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.write.ExcelBuilderImpl.addContent(ExcelBuilderImpl.java:58) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:161) ~[easyexcel-2.2.10.jar:na]
at com.alibaba.excel.ExcelWriter.write(ExcelWriter.java:146) ~[easyexcel-2.2.10.jar:na]