问题描述
: Can not find ‘Converter’ support class List.
问题解释
EasyExcel开源框架中Converter接口的convertToExcelData只实现了转换BigDecimal、Bolean、Byte[]、btye[]、Byte、Date、Double、File、Float、InputStream、Integer、Long、Short、URL这些类型,意味着参数data最多只能是个二维数据,但是本次业务逻辑需要转换List< String >的数据。
实体类数据
/**
* 名下企业名称
*/
@ExcelProperty(value = "名下企业名称",index = 12)
private List<String> enterpriseList;
解决办法
编写自定义Converter转换器:
@Component
public class ListConverter implements Converter<List> {
@Override
public Class supportJavaTypeKey() {
return ;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return ;
}
@Override
public List convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
String stringValue = ();
String[] split = (",");
List<String> enterpriseList = new ArrayList<>();
for(int i = 0; i < ; i++){
(split[i]);
}
return enterpriseList;
}
@Override
public CellData convertToExcelData(List list, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
StringBuilder stringBuilder = new StringBuilder();
(o -> {
String s = ();
(s+",");
});
return new CellData(());
}
}