diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 6b17fd8b..0f3e53b6 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -98,7 +98,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { if (dataIndex >= oneRowData.size()) { return; } - if (cellIndex != 0) { + if (dataIndex != 0) { cellIndex++; } int size = oneRowData.size() - dataIndex; diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index 1bf11fe4..ec124a43 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/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()); } + @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> noModelOneHead() { + List> list = new ArrayList>(); + List head0 = new ArrayList(); + head0.add("表头1"); + list.add(head0); + return list; + } + /** * 不创建对象的写 */