Browse Source

Merge pull request #1885 from SmireG/bugfix1765

fix #1765
developing
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
9286b57b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
  2. BIN
      src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx
  3. 55
      src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Issue1765.java

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

@ -142,7 +142,7 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
continue; continue;
} }
alreadyRangeSet.add(i + "-" + j); alreadyRangeSet.add(i + "-" + j);
String headName = headNameList.get(j); String headName = headNameList.get(j) == null ? "" : headNameList.get(j);
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++) {

BIN
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx

Binary file not shown.

55
src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Issue1765.java

@ -0,0 +1,55 @@
package com.alibaba.easyexcel.test.demo.Test1765;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Issue1765 {
@Test
public void test1765() throws FileNotFoundException {
String fileName = "src/test/java/com/alibaba/easyexcel/test/demo/Test1765/Data1765.xlsx";
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>();
List<String> head2 = new ArrayList<String>();
List<String> head3 = new ArrayList<String>();
head0.add("表头");
head1.add("日期");
head2.add(null);
head3.add("数字");
list.add(head0);
list.add(head1);
list.add(head2);
list.add(head3);
return list;
}
private List<List<Object>> dataList() {
List<List<Object>> list = new ArrayList<List<Object>>();
for (int i = 0; i < 5; i++) {
List<Object> data = new ArrayList<Object>();
data.add("字符串" + i);
data.add(new Date());
data.add(i * 2);
data.add(i * 3);
list.add(data);
}
return list;
}
}
Loading…
Cancel
Save