Browse Source

第一列ctn no全部居中

ecss-tx
han\hanst 3 weeks ago
parent
commit
9c6023521b
  1. 45
      src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java
  2. 11
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java

45
src/main/java/com/xujie/sys/common/utils/ExcelTemplateALPHA.java

@ -428,10 +428,7 @@ public class ExcelTemplateALPHA {
style.setBorderBottom(BorderStyle.NONE);
style.setBorderTop(BorderStyle.NONE);
style.setWrapText(true);
// 箱单 A 列 CTN No 后面会单独居中;这里不要改共享样式的对齐,避免表头被带成左对齐
if (!(intRight && j == 0)) {
style.setAlignment(HorizontalAlignment.LEFT);
}
style.setAlignment(HorizontalAlignment.LEFT);
c.setCellStyle(style);
if (rangeStyle && j < 4) {
for (int mi = 0; mi < 3; mi++) {
@ -447,23 +444,6 @@ public class ExcelTemplateALPHA {
}
// 设置明细样式,因为明细是动态添加的,会有样式和模版偏差,此处主要是第2、3列的样式需要设置
if (cellStyle) {
// 箱单 A 列 CTN No 共用一份居中样式:箱号/托号是文本(如 1~1),不在数字列循环里。
// 明细默认左对齐,RFID 的 c1 还会重绘 A 列;循环后再覆盖,后续合并才能 clone 到居中。
XSSFCellStyle packingCtnNoStyle = null;
if (intRight) {
packingCtnNoStyle = workbook.createCellStyle();
packingCtnNoStyle.setBorderRight(BorderStyle.NONE);
packingCtnNoStyle.setBorderLeft(BorderStyle.MEDIUM);
packingCtnNoStyle.setBorderBottom(BorderStyle.NONE);
packingCtnNoStyle.setBorderTop(BorderStyle.NONE);
Font packingCtnNoFont = workbook.createFont();
packingCtnNoFont.setFontName("Arial");
packingCtnNoFont.setFontHeightInPoints((short) 10);
packingCtnNoStyle.setFont(packingCtnNoFont);
packingCtnNoStyle.setVerticalAlignment(VerticalAlignment.TOP);
packingCtnNoStyle.setAlignment(HorizontalAlignment.CENTER);
packingCtnNoStyle.setWrapText(true);
}
for (Integer dtlRow : dtlRows) {
XSSFCell c1 = sheet.getRow(dtlRow).getCell(cellStyle2?0:1);
if (c1 == null) {
@ -624,6 +604,16 @@ public class ExcelTemplateALPHA {
c7.setCellStyle(style7);
}
// 列表第一列 CTN No 居中(数字列从第5列才开始处理)
XSSFRow packingRow = sheet.getRow(dtlRow);
XSSFCell firstCol = packingRow == null ? null : packingRow.getCell(0);
if (firstCol != null) {
XSSFCellStyle firstColStyle = workbook.createCellStyle();
firstColStyle.cloneStyleFrom(firstCol.getCellStyle());
firstColStyle.setAlignment(HorizontalAlignment.CENTER);
firstCol.setCellStyle(firstColStyle);
}
// net_weight列(J列,索引9)保持顶部右对齐
/*XSSFRow row = sheet.getRow(dtlRow);
if (row != null) {
@ -638,19 +628,6 @@ public class ExcelTemplateALPHA {
}*/
}
}
// 放在明细样式循环之后,覆盖 RFID/Label 对 A 列的默认左对齐,再交给后续合并 clone
if (packingCtnNoStyle != null && dtlRowIndex >= 0 && !listVariables.isEmpty()) {
for (int r = dtlRowIndex; r < dtlRowIndex + listVariables.size(); r++) {
XSSFRow ctnRow = sheet.getRow(r);
if (ctnRow == null) {
continue;
}
XSSFCell ctnNoCell = ctnRow.getCell(0);
if (ctnNoCell != null) {
ctnNoCell.setCellStyle(packingCtnNoStyle);
}
}
}
}
if (delRight) {
int declarationCenterStartCol = declarationUnitPriceCols.isEmpty()

11
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelTXServiceImpl.java

@ -3166,13 +3166,12 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService {
template.addMergeRegion(boxStartIndex, boxEndIndex, 9);
// 毛重列(K列,索引10)
template.addMergeRegion(boxStartIndex, boxEndIndex, 10);
// 无托时 A 列是箱号:单行也注册合并样式,保证 CTN No 水平居中;合箱再纵向合并
if (!hasPalletData) {
template.addMergeRegion(boxStartIndex, boxEndIndex, 0, 2);
}
// 合箱:F列箱数按箱合并居中(有托时A列仍是托号,不能按箱合并A列)
if (boxEndIndex > boxStartIndex) {
template.addMergeRegion(boxStartIndex, boxEndIndex, 5);
if (!hasPalletData) {
template.addMergeRegion(boxStartIndex, boxEndIndex, 0);
}
}
}
// 托盘数列按托盘(seq_no)跨箱合并:一个托盘下多个箱共享同一托盘数
@ -3183,9 +3182,9 @@ public class CoDelExcelTXServiceImpl implements CoDelExcelTXService {
}
boolean isCurrentPalletEnd = (m == list.size() - 1) || !Objects.equals(palletSeqNo, nextPalletSeqNo);
if (isCurrentPalletEnd && palletStartIndex >= 0 && boxEndIndex >= palletStartIndex) {
// 第一列托号按托盘合并(一个托可能有多个箱);alignType=2 水平居中
// 第一列托号按托盘合并(一个托可能有多个箱)
if (hasPalletData) {
template.addMergeRegion(palletStartIndex, boxEndIndex, 0, 2);
template.addMergeRegion(palletStartIndex, boxEndIndex, 0);
}
// 托盘列(倒数第3列,索引6)按托盘合并
template.addMergeRegion(palletStartIndex, boxEndIndex, 8);

Loading…
Cancel
Save