diff --git a/src/main/java/com/alibaba/excel/metadata/CellRange.java b/src/main/java/com/alibaba/excel/metadata/CellRange.java index 6805526e..bd0f54f9 100644 --- a/src/main/java/com/alibaba/excel/metadata/CellRange.java +++ b/src/main/java/com/alibaba/excel/metadata/CellRange.java @@ -1,8 +1,11 @@ package com.alibaba.excel.metadata; +import lombok.Data; + /** * @author jipengfei */ +@Data public class CellRange { private int firstRow; @@ -16,36 +19,4 @@ public class CellRange { this.firstCol = firstCol; this.lastCol = lastCol; } - - public int getFirstRow() { - return firstRow; - } - - public void setFirstRow(int firstRow) { - this.firstRow = firstRow; - } - - public int getLastRow() { - return lastRow; - } - - public void setLastRow(int lastRow) { - this.lastRow = lastRow; - } - - public int getFirstCol() { - return firstCol; - } - - public void setFirstCol(int firstCol) { - this.firstCol = firstCol; - } - - public int getLastCol() { - return lastCol; - } - - public void setLastCol(int lastCol) { - this.lastCol = lastCol; - } } diff --git a/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java b/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java index bb8f528b..c2779136 100644 --- a/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java +++ b/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java @@ -146,19 +146,21 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty { int lastCol = i; int lastRow = j; for (int k = i + 1; k < headList.size(); k++) { - boolean flag = (j - 1 >= 0) && !headList.get(k).getHeadNameList().get(j - 1).equals(headName); - if (headList.get(k).getHeadNameList().get(j).equals(headName) && flag) { - alreadyRangeSet.add(k + "-" + j); + String key = k + "-" + j; + if (headList.get(k).getHeadNameList().get(j).equals(headName) && !alreadyRangeSet.contains(key)) { + alreadyRangeSet.add(key); lastCol = k; } else { break; } } - Set tempAlreadyRangeSet = new HashSet(); + Set tempAlreadyRangeSet = new HashSet<>(); outer: for (int k = j + 1; k < headNameList.size(); k++) { for (int l = i; l <= lastCol; l++) { - if (headList.get(l).getHeadNameList().get(k).equals(headName)) { + String key = l + "-" + k; + if (headList.get(l).getHeadNameList().get(k).equals(headName) && !alreadyRangeSet.contains( + key)) { tempAlreadyRangeSet.add(l + "-" + k); } else { break outer; diff --git a/update.md b/update.md index 7192df0d..4d4d96dc 100644 --- a/update.md +++ b/update.md @@ -18,6 +18,8 @@ * cglib 新增命名策略,防止和`spring`的冲突 [Issue #2064](https://github.com/alibaba/easyexcel/issues/2064) * 修改填充可能填充错误的bug [Issue #2035](https://github.com/alibaba/easyexcel/issues/2035) * 修复无对象读 返回map的size可能会头的size不一致 [Issue #2014](https://github.com/alibaba/easyexcel/issues/2014) +* 修复合并头可能异常的bug [Issue #1662](https://github.com/alibaba/easyexcel/issues/1662) + # 2.2.10 * 修复读取的时候用string接收数字 可能四舍五入不一致的bug