diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java index 2cf7d773..0c1f58b2 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java @@ -580,18 +580,43 @@ public class CoDelServiceImpl implements CoDelService { if (cell == null) return null; try { - if (cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) { + CellType cellType = cell.getCellType(); + + // 处理数值类型(日期格式) + if (cellType == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)) { return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - } else if (cell.getCellType() == CellType.STRING) { + } + // 处理字符串类型 + else if (cellType == CellType.STRING) { String val = cell.getStringCellValue().trim(); if (val.isEmpty()) return null; return LocalDate.parse(val, DateTimeFormatter.ofPattern("yyyy-MM-dd")); } + // 处理公式类型 - 获取缓存结果 + else if (cellType == CellType.FORMULA) { + switch (cell.getCachedFormulaResultType()) { + case NUMERIC: + // 公式结果是数值类型且是日期格式 + if (DateUtil.isCellDateFormatted(cell)) { + return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + } + break; + case STRING: + // 公式结果是字符串类型 + String formulaVal = cell.getStringCellValue().trim(); + if (!formulaVal.isEmpty()) { + return LocalDate.parse(formulaVal, DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + break; + default: + break; + } + } } catch (Exception e) { System.err.println("日期格式解析失败: " + cell.toString()); } - return null; // 无法解析,返回 null 或抛异常 + return null; // 无法解析,返回 null }