excel插件 优化合并策略 在合适的生命周期完成合并 去除被合并单元格的非首行内容

This commit is contained in:
songshuang 2024-01-16 17:55:21 +08:00
parent 76a3663f3a
commit 81263bf405

View File

@ -45,6 +45,7 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
//单元格写入了,遍历合并区域,如果该Cell在区域内,但非首行,则清空
final int rowIndex = cell.getRowIndex();
if (CollUtil.isNotEmpty(cellList)){
for (CellRangeAddress cellAddresses : cellList) {
final int firstRow = cellAddresses.getFirstRow();
if (cellAddresses.isInRange(cell) && rowIndex != firstRow){
@ -52,14 +53,17 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook
}
}
}
}
@Override
public void afterWorkbookDispose(final WorkbookWriteHandlerContext context) {
//当前表格写完后统一写入
if (CollUtil.isNotEmpty(cellList)){
for (CellRangeAddress item : cellList) {
context.getWriteContext().writeSheetHolder().getSheet().addMergedRegion(item);
}
}
}
@SneakyThrows
private List<CellRangeAddress> handle(List<?> list, boolean hasTitle) {