|
|
|
@ -761,22 +761,19 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
} |
|
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
|
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; |
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
|
// 公式结果是数值类型且是日期格式 |
|
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
|
return cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
|
} |
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
|
// 公式结果是字符串类型 |
|
|
|
String formulaVal = cell.getStringCellValue().trim(); |
|
|
|
if (!formulaVal.isEmpty()) { |
|
|
|
return LocalDate.parse(formulaVal, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
@ -811,32 +808,33 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
|
|
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
|
if (cellType == CellType.FORMULA) { |
|
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
case NUMERIC: |
|
|
|
// 公式结果是数值类型 - 直接获取数值并转换为字符串 |
|
|
|
// 检查是否是日期格式 |
|
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
|
DataFormatter formatter = new DataFormatter(); |
|
|
|
return formatter.formatCellValue(cell); |
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
|
// 公式结果是数值类型 - 直接获取数值并转换为字符串 |
|
|
|
// 检查是否是日期格式 |
|
|
|
if (DateUtil.isCellDateFormatted(cell)) { |
|
|
|
DataFormatter formatter = new DataFormatter(); |
|
|
|
return formatter.formatCellValue(cell); |
|
|
|
} else { |
|
|
|
// 普通数值,转换为字符串(去除小数点后的零) |
|
|
|
double numericValue = cell.getNumericCellValue(); |
|
|
|
// 如果是整数,去掉.0 |
|
|
|
if (numericValue == Math.floor(numericValue)) { |
|
|
|
return String.valueOf((long) numericValue); |
|
|
|
} else { |
|
|
|
// 普通数值,转换为字符串(去除小数点后的零) |
|
|
|
double numericValue = cell.getNumericCellValue(); |
|
|
|
// 如果是整数,去掉.0 |
|
|
|
if (numericValue == Math.floor(numericValue)) { |
|
|
|
return String.valueOf((long) numericValue); |
|
|
|
} else { |
|
|
|
return String.valueOf(numericValue); |
|
|
|
} |
|
|
|
return String.valueOf(numericValue); |
|
|
|
} |
|
|
|
case STRING: |
|
|
|
// 公式结果是字符串类型 |
|
|
|
return cell.getStringCellValue(); |
|
|
|
case BLANK: |
|
|
|
return ""; |
|
|
|
case BOOLEAN: |
|
|
|
return String.valueOf(cell.getBooleanCellValue()); |
|
|
|
default: |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
|
// 公式结果是字符串类型 |
|
|
|
return cell.getStringCellValue(); |
|
|
|
} else if (cachedType == CellType.BLANK) { |
|
|
|
return ""; |
|
|
|
} else if (cachedType == CellType.BOOLEAN) { |
|
|
|
return String.valueOf(cell.getBooleanCellValue()); |
|
|
|
} else { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -869,17 +867,18 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
|
|
|
|
// 处理公式类型 - 获取缓存结果 |
|
|
|
if (cellType == CellType.FORMULA) { |
|
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
case NUMERIC: |
|
|
|
return (int) Math.round(cell.getNumericCellValue()); |
|
|
|
case STRING: |
|
|
|
try { |
|
|
|
return Integer.parseInt(cell.getStringCellValue().trim()); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
default: |
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
|
return (int) Math.round(cell.getNumericCellValue()); |
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
|
try { |
|
|
|
return Integer.parseInt(cell.getStringCellValue().trim()); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} else { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -911,11 +910,32 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
boolean isRequiredColumn = columnName != null && |
|
|
|
("Qty (pcs)".equalsIgnoreCase(columnName) || "TP".equalsIgnoreCase(columnName)); |
|
|
|
|
|
|
|
switch (cell.getCellType()) { |
|
|
|
case NUMERIC: |
|
|
|
BigDecimal value = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
|
return value.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
case STRING: |
|
|
|
CellType cellType = cell.getCellType(); |
|
|
|
|
|
|
|
if (cellType == CellType.NUMERIC) { |
|
|
|
BigDecimal value = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
|
return value.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
} else if (cellType == CellType.STRING) { |
|
|
|
try { |
|
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
BigDecimal stringValue = new BigDecimal(cell.getStringCellValue()); |
|
|
|
return stringValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
if (isRequiredColumn) { |
|
|
|
throw new RuntimeException("[" + columnName + "] 列无效的数值格式: " + cell.getStringCellValue()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} else if (cellType == CellType.FORMULA) { |
|
|
|
// 获取缓存结果 |
|
|
|
CellType cachedType = cell.getCachedFormulaResultType(); |
|
|
|
|
|
|
|
if (cachedType == CellType.NUMERIC) { |
|
|
|
BigDecimal formulaValue = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
|
return formulaValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
} else if (cachedType == CellType.STRING) { |
|
|
|
try { |
|
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
|
return null; |
|
|
|
@ -928,35 +948,16 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
case FORMULA: |
|
|
|
// 获取缓存结果 |
|
|
|
switch (cell.getCachedFormulaResultType()) { |
|
|
|
case NUMERIC: |
|
|
|
BigDecimal formulaValue = BigDecimal.valueOf(cell.getNumericCellValue()); |
|
|
|
return formulaValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
case STRING: |
|
|
|
try { |
|
|
|
if (cell.getStringCellValue() == null || cell.getStringCellValue().isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
BigDecimal stringValue = new BigDecimal(cell.getStringCellValue()); |
|
|
|
return stringValue.setScale(6, RoundingMode.HALF_UP); // 四舍五入保留四位小数 |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
if (isRequiredColumn) { |
|
|
|
throw new RuntimeException("[" + columnName + "] 列无效的数值格式: " + cell.getStringCellValue()); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
default: |
|
|
|
return null; |
|
|
|
} |
|
|
|
default: |
|
|
|
// 如果是必填列,抛出异常提示 |
|
|
|
if (isRequiredColumn) { |
|
|
|
throw new RuntimeException("[" + columnName + "] 列不支持的单元格类型: " + cell.getCellType()); |
|
|
|
} |
|
|
|
// 其他非必填列返回null |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果是必填列,抛出异常提示 |
|
|
|
if (isRequiredColumn) { |
|
|
|
throw new RuntimeException("[" + columnName + "] 列不支持的单元格类型: " + cell.getCellType()); |
|
|
|
} |
|
|
|
// 其他非必填列返回null |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|