Browse Source

拆箱场景下,第4-8列的行高设置为较矮的高度

java8
han\hanst 3 weeks ago
parent
commit
61e3b9c87f
  1. 32
      src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java
  2. 5
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java

32
src/main/java/com/xujie/sys/common/utils/ExcelTemplate.java

@ -23,6 +23,8 @@ public class ExcelTemplate {
private List<Map<String, Object>> listVariables = new ArrayList<>(); private List<Map<String, Object>> listVariables = new ArrayList<>();
// 存储需要合并的单元格区域信息[列表起始索引, 列表结束索引, 列索引] // 存储需要合并的单元格区域信息[列表起始索引, 列表结束索引, 列索引]
private List<int[]> mergeRegions = new ArrayList<>(); private List<int[]> mergeRegions = new ArrayList<>();
// 存储需要设置行高的行信息[起始行索引, 结束行索引, 行高]
private List<int[]> rowHeights = new ArrayList<>();
// 是否下移形状格式 // 是否下移形状格式
@Setter @Setter
private boolean moveShape = false; private boolean moveShape = false;
@ -117,10 +119,23 @@ public class ExcelTemplate {
} }
} }
/**
* 设置行高
* @param startListIndex 起始行索引相对于listVariables
* @param endListIndex 结束行索引相对于listVariables
* @param height 行高单位
*/
public void setRowHeight(int startListIndex, int endListIndex, int height) {
if (startListIndex <= endListIndex) {
rowHeights.add(new int[]{startListIndex, endListIndex, height});
}
}
public void clearAll(){ public void clearAll(){
variables.clear(); variables.clear();
listVariables.clear(); listVariables.clear();
mergeRegions.clear(); mergeRegions.clear();
rowHeights.clear();
moveShape = false; moveShape = false;
moveSeal = false; moveSeal = false;
cellStyle = false; cellStyle = false;
@ -640,6 +655,23 @@ public class ExcelTemplate {
} }
} }
// 处理行高设置
if (dtlRowIndex >= 0 && !rowHeights.isEmpty()) {
for (int[] heightInfo : rowHeights) {
int startRow = dtlRowIndex + heightInfo[0];
int endRow = dtlRowIndex + heightInfo[1];
int height = heightInfo[2];
for (int rowIdx = startRow; rowIdx <= endRow; rowIdx++) {
XSSFRow row = sheet.getRow(rowIdx);
if (row != null) {
// 设置行高Excel行高单位是1/20点所以需要乘以20
row.setHeight((short) (height * 20));
}
}
}
}
return workbook; return workbook;
} }
} }

5
src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java

@ -3018,6 +3018,11 @@ public class CoDelExcelServiceImpl implements CoDelExcelService {
// 合并列1-3参数顺序是 startRow, endRow, startCol, endCol, alignType // 合并列1-3参数顺序是 startRow, endRow, startCol, endCol, alignType
template.addMergeRegion(firstRow, lastRow, 1, 3, 1); template.addMergeRegion(firstRow, lastRow, 1, 3, 1);
System.out.println(" -> 已合并列1-3(行" + firstRow + "到" + lastRow + ")"); System.out.println(" -> 已合并列1-3(行" + firstRow + "到" + lastRow + ")");
// 拆箱场景下第4-8列的行高设置为较矮的高度
// 只有拆箱情况才需要调整行高
template.setRowHeight(firstRow, lastRow, boxSeqNos.size()>2?18:26);
System.out.println(" -> 已设置行高(行" + firstRow + "到" + lastRow + "):15点");
} else { } else {
System.out.println(" -> 跳过合并:firstRow=" + firstRow + ", lastRow=" + lastRow); System.out.println(" -> 跳过合并:firstRow=" + firstRow + ", lastRow=" + lastRow);
} }

Loading…
Cancel
Save