Browse Source

修复合并头可能异常的bug

developing
Jiaju Zhuang 3 years ago
parent
commit
3f2f21f955
  1. 35
      src/main/java/com/alibaba/excel/metadata/CellRange.java
  2. 12
      src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
  3. 2
      update.md

35
src/main/java/com/alibaba/excel/metadata/CellRange.java

@ -1,8 +1,11 @@
package com.alibaba.excel.metadata; package com.alibaba.excel.metadata;
import lombok.Data;
/** /**
* @author jipengfei * @author jipengfei
*/ */
@Data
public class CellRange { public class CellRange {
private int firstRow; private int firstRow;
@ -16,36 +19,4 @@ public class CellRange {
this.firstCol = firstCol; this.firstCol = firstCol;
this.lastCol = lastCol; 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;
}
} }

12
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java

@ -146,19 +146,21 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
int lastCol = i; int lastCol = i;
int lastRow = j; int lastRow = j;
for (int k = i + 1; k < headList.size(); k++) { for (int k = i + 1; k < headList.size(); k++) {
boolean flag = (j - 1 >= 0) && !headList.get(k).getHeadNameList().get(j - 1).equals(headName); String key = k + "-" + j;
if (headList.get(k).getHeadNameList().get(j).equals(headName) && flag) { if (headList.get(k).getHeadNameList().get(j).equals(headName) && !alreadyRangeSet.contains(key)) {
alreadyRangeSet.add(k + "-" + j); alreadyRangeSet.add(key);
lastCol = k; lastCol = k;
} else { } else {
break; break;
} }
} }
Set<String> tempAlreadyRangeSet = new HashSet<String>(); Set<String> tempAlreadyRangeSet = new HashSet<>();
outer: outer:
for (int k = j + 1; k < headNameList.size(); k++) { for (int k = j + 1; k < headNameList.size(); k++) {
for (int l = i; l <= lastCol; l++) { 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); tempAlreadyRangeSet.add(l + "-" + k);
} else { } else {
break outer; break outer;

2
update.md

@ -18,6 +18,8 @@
* cglib 新增命名策略,防止和`spring`的冲突 [Issue #2064](https://github.com/alibaba/easyexcel/issues/2064) * cglib 新增命名策略,防止和`spring`的冲突 [Issue #2064](https://github.com/alibaba/easyexcel/issues/2064)
* 修改填充可能填充错误的bug [Issue #2035](https://github.com/alibaba/easyexcel/issues/2035) * 修改填充可能填充错误的bug [Issue #2035](https://github.com/alibaba/easyexcel/issues/2035)
* 修复无对象读 返回map的size可能会头的size不一致 [Issue #2014](https://github.com/alibaba/easyexcel/issues/2014) * 修复无对象读 返回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 # 2.2.10
* 修复读取的时候用string接收数字 可能四舍五入不一致的bug * 修复读取的时候用string接收数字 可能四舍五入不一致的bug

Loading…
Cancel
Save