Browse Source

Merge pull request #1877 from JackeyXps/master

fix issue#1702 不创建对象的写,无法正常写入数据
developing
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
39c9d47d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  2. 16
      src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

2
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java

@ -98,7 +98,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
if (dataIndex >= oneRowData.size()) { if (dataIndex >= oneRowData.size()) {
return; return;
} }
if (cellIndex != 0) { if (dataIndex != 0) {
cellIndex++; cellIndex++;
} }
int size = oneRowData.size() - dataIndex; int size = oneRowData.size() - dataIndex;

16
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -601,6 +601,22 @@ public class WriteTest {
EasyExcel.write(fileName, ConverterData.class).head(variableTitleHead()).sheet("模板").doWrite(data()); EasyExcel.write(fileName, ConverterData.class).head(variableTitleHead()).sheet("模板").doWrite(data());
} }
@Test
public void noModelWriteWithOneHead() {
// 写法1
String fileName = TestFileUtil.getPath() + "noModelSimpleWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName).head(noModelOneHead()).sheet("模板").doWrite(dataList());
}
private List<List<String>> noModelOneHead() {
List<List<String>> list = new ArrayList<List<String>>();
List<String> head0 = new ArrayList<String>();
head0.add("表头1");
list.add(head0);
return list;
}
/** /**
* 不创建对象的写 * 不创建对象的写
*/ */

Loading…
Cancel
Save