Commit 002172af5f0d45c5c9413752de0279f20eb0a8f6

Authored by dadiyang
1 parent fa99e965

fix(excel):A43第二处根因——AreaConvert 补 convertToExcelData(写方向)

导入模板下载恒500有两处独立根因:(1)空字典下拉拼出 $F$1:$F$0 非法区间致
FormulaParseException(已由 SelectSheetWriteHandler 跳过空字典修复);(2)修复(1)后暴露
第二处——bankAreaId 列用 AreaConvert,但 AreaConvert 只实现了 convertToJavaData(读),
未实现 convertToExcelData(写),生成模板写示例数据时抛 UnsupportedOperationException。
现补 convertToExcelData:地区编号经 AreaUtils.format(id,"/") 转全路径,与读方向
parseArea 的 "/" 分隔一致可往返。
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/convert/AreaConvert.java
... ... @@ -7,6 +7,7 @@ import cn.idev.excel.converters.Converter;
7 7 import cn.idev.excel.enums.CellDataTypeEnum;
8 8 import cn.idev.excel.metadata.GlobalConfiguration;
9 9 import cn.idev.excel.metadata.data.ReadCellData;
  10 +import cn.idev.excel.metadata.data.WriteCellData;
10 11 import cn.idev.excel.metadata.property.ExcelContentProperty;
11 12 import lombok.extern.slf4j.Slf4j;
12 13  
... ... @@ -43,4 +44,21 @@ public class AreaConvert implements Converter<Object> {
43 44 return Convert.convert(fieldClazz, area.getId());
44 45 }
45 46  
  47 + @Override
  48 + public WriteCellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty,
  49 + GlobalConfiguration globalConfiguration) {
  50 + // 空时,返回空
  51 + if (object == null) {
  52 + return new WriteCellData<>("");
  53 + }
  54 + // 将地区编号转换成地区全路径(与 convertToJavaData 的 parseArea 对应,使用 "/" 分隔)
  55 + Integer id = Convert.convert(Integer.class, object);
  56 + String path = AreaUtils.format(id, "/");
  57 + if (path == null) {
  58 + log.error("[convertToExcelData][id({}) 转换不了]", id);
  59 + return new WriteCellData<>("");
  60 + }
  61 + return new WriteCellData<>(path);
  62 + }
  63 +
46 64 }
... ...