|
|
@ -580,18 +580,43 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
if (cell == null) return null; |
|
|
if (cell == null) return null; |
|
|
|
|
|
|
|
|
try { |
|
|
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(); |
|
|
return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
} else if (cell.getCellType() == CellType.STRING) { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
// 处理字符串类型 |
|
|
|
|
|
else if (cellType == CellType.STRING) { |
|
|
String val = cell.getStringCellValue().trim(); |
|
|
String val = cell.getStringCellValue().trim(); |
|
|
if (val.isEmpty()) return null; |
|
|
if (val.isEmpty()) return null; |
|
|
return LocalDate.parse(val, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
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) { |
|
|
} catch (Exception e) { |
|
|
System.err.println("日期格式解析失败: " + cell.toString()); |
|
|
System.err.println("日期格式解析失败: " + cell.toString()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return null; // 无法解析,返回 null 或抛异常 |
|
|
|
|
|
|
|
|
return null; // 无法解析,返回 null |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|