|
|
@ -761,22 +761,19 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
} |
|
|
} |
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
else if (cellType == CellType.FORMULA) { |
|
|
else if (cellType == CellType.FORMULA) { |
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
|
|
case NUMERIC: |
|
|
|
|
|
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
// 公式结果是数值类型且是日期格式 |
|
|
// 公式结果是数值类型且是日期格式 |
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
case STRING: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
// 公式结果是字符串类型 |
|
|
// 公式结果是字符串类型 |
|
|
String formulaVal = cell.getStringCellValue().trim(); |
|
|
String formulaVal = cell.getStringCellValue().trim(); |
|
|
if (!formulaVal.isEmpty()) { |
|
|
if (!formulaVal.isEmpty()) { |
|
|
return LocalDate.parse(formulaVal, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
return LocalDate.parse(formulaVal, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
@ -811,8 +808,9 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
|
|
|
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
if (cellType == CellType.FORMULA) { |
|
|
if (cellType == CellType.FORMULA) { |
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
|
|
case NUMERIC: |
|
|
|
|
|
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
// 公式结果是数值类型 - 直接获取数值并转换为字符串 |
|
|
// 公式结果是数值类型 - 直接获取数值并转换为字符串 |
|
|
// 检查是否是日期格式 |
|
|
// 检查是否是日期格式 |
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
@ -828,14 +826,14 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
return String.valueOf(numericValue); |
|
|
return String.valueOf(numericValue); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
case STRING: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
// 公式结果是字符串类型 |
|
|
// 公式结果是字符串类型 |
|
|
return cell.getStringCellValue(); |
|
|
return cell.getStringCellValue(); |
|
|
case BLANK: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.BLANK) { |
|
|
return ""; |
|
|
return ""; |
|
|
case BOOLEAN: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.BOOLEAN) { |
|
|
return String.valueOf(cell.getBooleanCellValue()); |
|
|
return String.valueOf(cell.getBooleanCellValue()); |
|
|
default: |
|
|
|
|
|
|
|
|
} else { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -869,16 +867,17 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
|
|
|
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
if (cellType == CellType.FORMULA) { |
|
|
if (cellType == CellType.FORMULA) { |
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
|
|
case NUMERIC: |
|
|
|
|
|
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
return (int) Math.round(cell.getNumericCellValue()); |
|
|
return (int) Math.round(cell.getNumericCellValue()); |
|
|
case STRING: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
try { |
|
|
try { |
|
|
return Integer.parseInt(cell.getStringCellValue().trim()); |
|
|
return Integer.parseInt(cell.getStringCellValue().trim()); |
|
|
} catch (NumberFormatException e) { |
|
|
} catch (NumberFormatException e) { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
default: |
|
|
|
|
|
|
|
|
} else { |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -911,11 +910,12 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
boolean isRequiredColumn = columnName != null && |
|
|
boolean isRequiredColumn = columnName != null && |
|
|
("Qty (pcs)".equalsIgnoreCase(columnName) || "TP".equalsIgnoreCase(columnName)); |
|
|
("Qty (pcs)".equalsIgnoreCase(columnName) || "TP".equalsIgnoreCase(columnName)); |
|
|
|
|
|
|
|
|
switch (cell.getCellType()) { |
|
|
|
|
|
case NUMERIC: |
|
|
|
|
|
|
|
|
CellType cellType = cell.getCellType(); |
|
|
|
|
|
|
|
|
|
|
|
if (cellType == CellType.NUMERIC) { |
|
|
BigDecimal value = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
BigDecimal value = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
return value.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
return value.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
case STRING: |
|
|
|
|
|
|
|
|
} else if (cellType == CellType.STRING) { |
|
|
try { |
|
|
try { |
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
return null; |
|
|
return null; |
|
|
@ -928,13 +928,14 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
case FORMULA: |
|
|
|
|
|
|
|
|
} else if (cellType == CellType.FORMULA) { |
|
|
// 获取缓存结果 |
|
|
// 获取缓存结果 |
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
|
|
case NUMERIC: |
|
|
|
|
|
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
BigDecimal formulaValue = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
BigDecimal formulaValue = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
return formulaValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
return formulaValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
case STRING: |
|
|
|
|
|
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
try { |
|
|
try { |
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
return null; |
|
|
return null; |
|
|
@ -947,10 +948,10 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
default: |
|
|
|
|
|
|
|
|
} else { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
default: |
|
|
|
|
|
|
|
|
} else { |
|
|
// 如果是必填列,抛出异常提示 |
|
|
// 如果是必填列,抛出异常提示 |
|
|
if (isRequiredColumn) { |
|
|
if (isRequiredColumn) { |
|
|
throw new RuntimeException("[" + columnName + "] 列不支持的单元格类型: " + cell.getCellType()); |
|
|
throw new RuntimeException("[" + columnName + "] 列不支持的单元格类型: " + cell.getCellType()); |
|
|
|