From c09fa604336ab78039857240aee03a700f6d9a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 19 Dec 2025 13:08:27 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=E5=8D=95=E5=85=83=E6=A0=BC=E5=90=88=E5=B9=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/excel/core/CellMergeHandler.java | 20 +++++++++++++++++++ .../common/excel/core/CellMergeStrategy.java | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeHandler.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeHandler.java index 1a0601479..d68f427c6 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeHandler.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeHandler.java @@ -30,6 +30,11 @@ public class CellMergeHandler { this.rowIndex = hasTitle ? 1 : 0; } + private CellMergeHandler(final boolean hasTitle, final int rowIndex) { + this.hasTitle = hasTitle; + this.rowIndex = hasTitle ? rowIndex : 0; + } + @SneakyThrows public List handle(List rows) { // 如果入参为空集合则返回空集 @@ -103,6 +108,10 @@ public class CellMergeHandler { } if (isAddResult && i > current) { + //如果是同一行,则跳过合并 + if (current + rowIndex == lastRow) { + continue; + } result.add(new CellRangeAddress(current + rowIndex, lastRow, colNum, colNum)); } } @@ -178,6 +187,17 @@ public class CellMergeHandler { } } + /** + * 创建一个单元格合并处理器实例 + * + * @param hasTitle 是否合并标题 + * @param rowIndex 行索引 + * @return 单元格合并处理器 + */ + public static CellMergeHandler of(final boolean hasTitle, final int rowIndex) { + return new CellMergeHandler(hasTitle, rowIndex); + } + /** * 创建一个单元格合并处理器实例 * 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 5576c6383..64d8c7779 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 @@ -31,6 +31,10 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements SheetWri this.cellList = CellMergeHandler.of(hasTitle).handle(list); } + public CellMergeStrategy(List list, boolean hasTitle, int rowIndex) { + this.cellList = CellMergeHandler.of(hasTitle, rowIndex).handle(list); + } + @Override protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) { if (CollUtil.isEmpty(cellList)) {