diff --git a/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java b/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java index 816efea6..d6451454 100644 --- a/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java +++ b/src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java @@ -34,9 +34,15 @@ public class ExcelTemplate { // 是否设置合并单元格样式 @Setter private boolean rangeStyle = false; - // 价格靠右 + // 价格靠右 发票 @Setter private boolean priceRight = false; + // 数字靠右 箱单 + @Setter + private boolean intRight = false; + // 报关单 + @Setter + private boolean delRight = false; private ExcelTemplate(){} @@ -190,14 +196,29 @@ public class ExcelTemplate { if ("#{pn}".equals(cellValue)) { dtlRows.add(i); } + if ("#{levy}".equals(cellValue)) { + dtlRows.add(i); + } Matcher matcherHdr = PATTERN_HDR_FIELD.matcher(cellValue); + String result = c.getStringCellValue(); while (matcherHdr.find()) { for (int ri = 1; ri <= matcherHdr.groupCount(); ri++) { String field = matcherHdr.group(ri); - //all cell in string now, can be set to different type of values - c.setCellValue(c.toString().replace(matcherHdr.group(0), String.valueOf(variables.getOrDefault(field, "")))); + Object value = variables.getOrDefault(field, ""); + result = result.replace(matcherHdr.group(0), String.valueOf(value)); + } + if ("${phone1}".equals(cellValue) || "${phone2}".equals(cellValue) || "${hs_code}".equals(cellValue)) { + c.setCellValue(result); // 字符串 + } else { + try { + double num = Double.parseDouble(result.replace(",", "")); + c.setCellValue(num); // 数值 + } catch (NumberFormatException e) { + c.setCellValue(result); // 字符串 + } } } + Matcher matcherDtl = PATTERN_DTL_FIELD.matcher(cellValue); while (matcherDtl.find()) { for (int ri = 1; ri <= matcherDtl.groupCount(); ri++) { @@ -262,22 +283,130 @@ public class ExcelTemplate { style2.setWrapText(true); c2.setCellStyle(style2); if (priceRight) { //仅供发票excel使用,第8、9是价格列居右 - for (int i = 7; i < 9; i++) { + for (int i = 6; i < 9; i++) { XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); if (c7 == null) { continue; } + + // 尝试把字符串转成数值 + if (c7.getCellType() == CellType.STRING) { + String strVal = c7.getStringCellValue(); + if (strVal != null && !strVal.trim().isEmpty()) { + try { + double num = Double.parseDouble(strVal.replace(",", "")); + c7.setCellValue(num); // 转换为数值写回 + } catch (NumberFormatException e) { + // 如果不是数字就保留原字符串 + System.out.println("非数字,保持原值: " + strVal); + } + } + } + + // 创建样式 XSSFCellStyle style7 = workbook.createCellStyle(); style7.setBorderRight(BorderStyle.MEDIUM); style7.setBorderLeft(BorderStyle.NONE); style7.setBorderBottom(BorderStyle.NONE); style7.setBorderTop(BorderStyle.NONE); + Font font7 = workbook.createFont(); - font7.setFontName("Arial"); // 设置字体 - font7.setFontHeightInPoints((short) 10); // 设置字号 + font7.setFontName("Arial"); + font7.setFontHeightInPoints((short) 10); style7.setFont(font7); + style7.setVerticalAlignment(VerticalAlignment.TOP); style7.setAlignment(HorizontalAlignment.RIGHT); + + // 设置千分位格式 + DataFormat dataFormat = workbook.createDataFormat(); + style7.setDataFormat(i==6?dataFormat.getFormat("#,##0.0"):dataFormat.getFormat("#,##0.00")); + + c7.setCellStyle(style7); + } + + } + if (intRight) { //仅供箱单excel使用 + for (int i = 4; i < 9; i++) { + XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); + if (c7 == null) { + continue; + } + // 尝试把字符串转成数值 + if (c7.getCellType() == CellType.STRING) { + String strVal = c7.getStringCellValue(); + if (strVal != null && !strVal.trim().isEmpty()) { + try { + double num = Double.parseDouble(strVal.replace(",", "")); + c7.setCellValue(num); // 转换为数值写回 + } catch (NumberFormatException e) { + // 如果不是数字就保留原字符串 + System.out.println("非数字,保持原值: " + strVal); + } + } + } + + // 创建样式 + XSSFCellStyle style7 = workbook.createCellStyle(); + style7.setBorderRight(BorderStyle.MEDIUM); + style7.setBorderLeft(i==4?BorderStyle.MEDIUM:BorderStyle.NONE); + style7.setBorderBottom(BorderStyle.NONE); + style7.setBorderTop(BorderStyle.NONE); + + Font font7 = workbook.createFont(); + font7.setFontName("Arial"); + font7.setFontHeightInPoints((short) 10); + style7.setFont(font7); + + style7.setVerticalAlignment(VerticalAlignment.TOP); + style7.setAlignment(HorizontalAlignment.RIGHT); + + // 设置千分位格式 + DataFormat dataFormat = workbook.createDataFormat(); + style7.setDataFormat(dataFormat.getFormat("#,##0.0")); + + c7.setCellStyle(style7); + } + + } + } + } + if (delRight) { + for (Integer dtlRow : dtlRows) { + for (int i = 6; i < 12; i++) { + if (i==6 || i==11) { + XSSFCell c7 = sheet.getRow(dtlRow).getCell(i); + if (c7 == null) { + continue; + } + // 尝试把字符串转成数值 + if (c7.getCellType() == CellType.STRING) { + String strVal = c7.getStringCellValue(); + if (strVal != null && !strVal.trim().isEmpty()) { + try { + double num = Double.parseDouble(strVal.replace(",", "")); + c7.setCellValue(num); // 转换为数值写回 + } catch (NumberFormatException e) { + // 如果不是数字就保留原字符串 + System.out.println("非数字,保持原值: " + strVal); + } + } + } + // 创建样式 + XSSFCellStyle style7 = workbook.createCellStyle(); + style7.setBorderRight(BorderStyle.NONE); + style7.setBorderLeft(BorderStyle.NONE); + style7.setBorderBottom(BorderStyle.NONE); + style7.setBorderTop(BorderStyle.NONE); + Font font7 = workbook.createFont(); + font7.setFontName("Arial"); + font7.setFontHeightInPoints((short) 10); + style7.setFont(font7); + style7.setVerticalAlignment(VerticalAlignment.CENTER); + style7.setAlignment(HorizontalAlignment.RIGHT); + // 设置千分位格式 + DataFormat dataFormat = workbook.createDataFormat(); + style7.setDataFormat(i==6?dataFormat.getFormat("#,##0.0"):dataFormat.getFormat("#,##0.00")); c7.setCellStyle(style7); } } 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 bf14fc9c..71d8d1ce 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 @@ -1647,6 +1647,7 @@ public class CoDelServiceImpl implements CoDelService { private void extractedDeclaration(EcssDeclarationHeaderData data, ExcelTemplate template) { template.setMoveSeal(true); + template.setDelRight(true); EcssDeclarationHeaderData ecHeader = coDelMapper.getDeclarationHeader(data); template.addVar("inputCode", stringInput(ecHeader.getInputCode())); template.addVar("customsOfficeCode", stringInput(ecHeader.getCustomsOfficeCode())); @@ -1898,6 +1899,7 @@ public class CoDelServiceImpl implements CoDelService { template.setCellStyle(true); template.setRangeStyle(true); template.setMoveSeal(true); + template.setIntRight(true); if (notifyHeader.getBuNo().equals("03-RFID") || notifyHeader.getBuNo().equals("01-Label")){ template.setCellStyle2(true); } diff --git a/src/main/resources/templates/declaration-all-seal-template.xlsx b/src/main/resources/templates/declaration-all-seal-template.xlsx index 44f39365..b0075110 100644 Binary files a/src/main/resources/templates/declaration-all-seal-template.xlsx and b/src/main/resources/templates/declaration-all-seal-template.xlsx differ diff --git a/src/main/resources/templates/declaration-all-template.xlsx b/src/main/resources/templates/declaration-all-template.xlsx index b0ba568a..e1d2e294 100644 Binary files a/src/main/resources/templates/declaration-all-template.xlsx and b/src/main/resources/templates/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/declaration-invoice-seal-template.xlsx b/src/main/resources/templates/declaration-invoice-seal-template.xlsx index 3fa3d605..27a2074c 100644 Binary files a/src/main/resources/templates/declaration-invoice-seal-template.xlsx and b/src/main/resources/templates/declaration-invoice-seal-template.xlsx differ diff --git a/src/main/resources/templates/declaration-invoice-template.xlsx b/src/main/resources/templates/declaration-invoice-template.xlsx index d543b485..9dad6003 100644 Binary files a/src/main/resources/templates/declaration-invoice-template.xlsx and b/src/main/resources/templates/declaration-invoice-template.xlsx differ diff --git a/src/main/resources/templates/declaration-packingList-template.xlsx b/src/main/resources/templates/declaration-packingList-template.xlsx index 0b0d3638..0ecc35e9 100644 Binary files a/src/main/resources/templates/declaration-packingList-template.xlsx and b/src/main/resources/templates/declaration-packingList-template.xlsx differ