Commit e6a3a14f473f91406c1109818abaceb9dfbb8ad2

Authored by 芋道源码
Committed by GitHub
2 parents 052c8f5d 002172af

Merge pull request #1217 from dadiyang/fix/hrm-import-template-empty-dict-skip

[FIX] Excel 框架:导入模板下拉对空字典/空选项源整列跳过+AreaConvert 补写方向(A43,惠及所有模板)
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 }
... ...
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java
... ... @@ -133,6 +133,11 @@ public class SelectSheetWriteHandler implements SheetWriteHandler {
133 133 DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); // 需要设置下拉框的 sheet 页的数据验证助手
134 134 Workbook workbook = writeWorkbookHolder.getWorkbook(); // 获得工作簿
135 135 List<KeyValue<Integer, List<String>>> keyValues = convertList(selectMap.entrySet(), entry -> new KeyValue<>(entry.getKey(), entry.getValue()));
  136 + // 空字典/空选项源:跳过该列下拉,避免拼出 $F$1:$F$0 非法区间致 POI FormulaParseException(该列退化为普通文本列)
  137 + keyValues.removeIf(item -> CollUtil.isEmpty(item.getValue()));
  138 + if (CollUtil.isEmpty(keyValues)) {
  139 + return; // 全部为空时连「字典sheet」都不创建
  140 + }
136 141 keyValues.sort(Comparator.comparing(item -> item.getValue().size())); // 升序不然创建下拉会报错
137 142  
138 143 // 2. 创建数据字典的 sheet 页
... ...