From 81263bf405d83f85c0402b31d1cd2da3292c4af6 Mon Sep 17 00:00:00 2001 From: songshuang Date: Tue, 16 Jan 2024 17:55:21 +0800 Subject: [PATCH] =?UTF-8?q?excel=E6=8F=92=E4=BB=B6=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E7=AD=96=E7=95=A5=20=E5=9C=A8=E5=90=88?= =?UTF-8?q?=E9=80=82=E7=9A=84=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=90=88=E5=B9=B6=20=E5=8E=BB=E9=99=A4=E8=A2=AB?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E5=8D=95=E5=85=83=E6=A0=BC=E7=9A=84=E9=9D=9E?= =?UTF-8?q?=E9=A6=96=E8=A1=8C=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/excel/core/CellMergeStrategy.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java index 7dde91523..d566d11cf 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java @@ -45,10 +45,12 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) { //单元格写入了,遍历合并区域,如果该Cell在区域内,但非首行,则清空 final int rowIndex = cell.getRowIndex(); - for (CellRangeAddress cellAddresses : cellList) { - final int firstRow = cellAddresses.getFirstRow(); - if (cellAddresses.isInRange(cell) && rowIndex != firstRow){ - cell.setBlank(); + if (CollUtil.isNotEmpty(cellList)){ + for (CellRangeAddress cellAddresses : cellList) { + final int firstRow = cellAddresses.getFirstRow(); + if (cellAddresses.isInRange(cell) && rowIndex != firstRow){ + cell.setBlank(); + } } } } @@ -56,8 +58,10 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook @Override public void afterWorkbookDispose(final WorkbookWriteHandlerContext context) { //当前表格写完后,统一写入 - for (CellRangeAddress item : cellList) { - context.getWriteContext().writeSheetHolder().getSheet().addMergedRegion(item); + if (CollUtil.isNotEmpty(cellList)){ + for (CellRangeAddress item : cellList) { + context.getWriteContext().writeSheetHolder().getSheet().addMergedRegion(item); + } } }