From 663e22ac294acf7a26ab2307b04ddd24700fd88b Mon Sep 17 00:00:00 2001 From: Simple <2424585654@qq.com> Date: Tue, 12 Dec 2023 16:58:24 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20excel=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=B3=A8=E8=A7=A3=E4=BC=9A=E6=A0=B9=E6=8D=AE=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E5=90=88=E5=B9=B6=E5=88=97=E7=9A=84=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=9D=A5=E5=86=B3=E5=AE=9A=E5=90=8E=E7=BB=AD=E7=9A=84=E5=88=97?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/excel/core/CellMergeStrategy.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 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 08f4dda26..bcb5be767 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 @@ -98,9 +98,30 @@ public class CellMergeStrategy extends AbstractMergeStrategy { cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum)); } map.put(field, new RepeatCell(val, i)); - } else if (i == list.size() - 1) { - if (i > repeatCell.getCurrent()) { - cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum)); + } else if (j == 0) { + if (i == list.size() - 1) { + if (i > repeatCell.getCurrent()) { + cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum)); + } + } + } else { + // 判断前面的是否合并了 + RepeatCell firstCell = map.get(mergeFields.get(0)); + if (repeatCell.getCurrent() != firstCell.getCurrent()) { + if (i == list.size() - 1) { + if (i > repeatCell.getCurrent()) { + cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum)); + } + } else if (repeatCell.getCurrent() < firstCell.getCurrent()) { + if (i - repeatCell.getCurrent() > 1) { + cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex - 1, colNum, colNum)); + } + map.put(field, new RepeatCell(val, i)); + } + } else if (i == list.size() - 1) { + if (i > repeatCell.getCurrent()) { + cellList.add(new CellRangeAddress(repeatCell.getCurrent() + rowIndex, i + rowIndex, colNum, colNum)); + } } } }