Browse Source

Merge pull request #1940 from lethal233/bugfix-1662

Bugfix #1662
developing
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
669508ba3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
  2. 20
      src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Data1662.java
  3. 42
      src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java

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

@ -146,7 +146,8 @@ 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++) {
if (headList.get(k).getHeadNameList().get(j).equals(headName)) { 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); alreadyRangeSet.add(k + "-" + j);
lastCol = k; lastCol = k;
} else { } else {

20
src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Data1662.java

@ -0,0 +1,20 @@
package com.alibaba.easyexcel.test.temp.issue1662;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Data1662 {
@ExcelProperty(index = 0)
private String str;
@ExcelProperty(index = 1)
private Date date;
@ExcelProperty(index = 2)
private double r;
}

42
src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java

@ -0,0 +1,42 @@
package com.alibaba.easyexcel.test.temp.issue1662;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Issue1662Test {
@Test
public void test1662() {
String fileName = TestFileUtil.getPath() + "Test1939" + ".xlsx";
System.out.println(fileName);
EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList());
}
private List<List<String>> head() {
List<List<String>> list = new ArrayList<List<String>>();
List<String> head0 = new ArrayList<String>();
List<String> head1 = new ArrayList<String>();
head0.add("xx");
head0.add("日期");
list.add(head0);
head1.add("日期");
list.add(head1);
return list;
}
private List<List<Object>> dataList() {
List<List<Object>> list = new ArrayList<List<Object>>();
List<Object> data = new ArrayList<Object>();
data.add("字符串");
data.add(new Date());
data.add(0.56);
list.add(data);
return list;
}
}
Loading…
Cancel
Save