From 38bd71c775bcd2a231762feebbcc4d70b4839d2a Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Mon, 1 Dec 2025 10:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=8F=AF=E4=BB=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=BC=93=E5=AD=98=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ecss/service/impl/CoDelServiceImpl.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) 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 }