|
|
|
@ -43,6 +43,9 @@ public class ExcelTemplate { |
|
|
|
// 报关单 |
|
|
|
@Setter |
|
|
|
private boolean delRight = false; |
|
|
|
// 箱单 |
|
|
|
@Setter |
|
|
|
private boolean boxFlag = false; |
|
|
|
|
|
|
|
private ExcelTemplate(){} |
|
|
|
|
|
|
|
@ -183,6 +186,7 @@ public class ExcelTemplate { |
|
|
|
} |
|
|
|
|
|
|
|
List<Integer> dtlRows = new ArrayList<>(); |
|
|
|
List<Integer> boxRows = new ArrayList<>(); |
|
|
|
//整体填值 |
|
|
|
for (int i = 0; i <= sheet.getLastRowNum(); i++) { |
|
|
|
XSSFRow row = sheet.getRow(i); |
|
|
|
@ -202,6 +206,9 @@ public class ExcelTemplate { |
|
|
|
if ("#{levy}".equals(cellValue)) { |
|
|
|
dtlRows.add(i); |
|
|
|
} |
|
|
|
if ("#{cmcInvoice}".equals(cellValue)) { |
|
|
|
boxRows.add(i); |
|
|
|
} |
|
|
|
Matcher matcherHdr = PATTERN_HDR_FIELD.matcher(cellValue); |
|
|
|
String result = c.getStringCellValue(); |
|
|
|
while (matcherHdr.find()) { |
|
|
|
@ -243,7 +250,7 @@ public class ExcelTemplate { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置样式 |
|
|
|
if (cellStyle && dtlRowIndex >= 0 && i >= dtlRowIndex && i < dtlRowIndex + listVariables.size()) { |
|
|
|
XSSFCellStyle style = c.getCellStyle(); |
|
|
|
@ -445,6 +452,54 @@ public class ExcelTemplate { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (boxFlag) { |
|
|
|
for (Integer dtlRow : boxRows) { |
|
|
|
for (int i = 1; i < 6; i++) { |
|
|
|
if (i==1 || i==4 || i==5) { |
|
|
|
XSSFRow row = sheet.getRow(dtlRow); |
|
|
|
if (row == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
XSSFCell c7 = row.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.THIN); |
|
|
|
style7.setBorderLeft(BorderStyle.THIN); |
|
|
|
style7.setBorderBottom(BorderStyle.THIN); |
|
|
|
style7.setBorderTop(BorderStyle.THIN); |
|
|
|
|
|
|
|
Font font7 = workbook.createFont(); |
|
|
|
font7.setFontName("DengXian"); // 等线 |
|
|
|
font7.setFontHeightInPoints((short) 11); // 11号 |
|
|
|
style7.setFont(font7); |
|
|
|
|
|
|
|
style7.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
style7.setAlignment(HorizontalAlignment.RIGHT); |
|
|
|
|
|
|
|
// 设置千分位格式 |
|
|
|
DataFormat dataFormat = workbook.createDataFormat(); |
|
|
|
style7.setDataFormat(dataFormat.getFormat("#,##0")); |
|
|
|
c7.setCellStyle(style7); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return workbook; |
|
|
|
} |
|
|
|
} |