From 0aa3dbbc4b98713a84f8d5812f9dcf7cd4e40701 Mon Sep 17 00:00:00 2001 From: JackeyXps <599591947@qq.com> Date: Sat, 17 Apr 2021 16:56:09 +0800 Subject: [PATCH 1/2] fixed write with only one head without Model issue1702 --- .../write/executor/ExcelWriteAddExecutor.java | 2 +- .../easyexcel/test/demo/write/WriteTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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 9f229029..84b9821d 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -93,7 +93,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { if (dataIndex >= oneRowData.size()) { return; } - if (cellIndex != 0) { + if (headMap.size() != 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 4bce5127..15811fcf 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 @@ -502,6 +502,22 @@ public class WriteTest { EasyExcel.write(fileName, ConverterData.class).head(variableTitleHead()).sheet("模板").doWrite(data()); } + @Test + public void noModelSimpleWriteWithOneHead() { + // 写法1 + String fileName = TestFileUtil.getPath() + "noModelSimpleWrite" + System.currentTimeMillis() + ".xlsx"; + // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 + EasyExcel.write(fileName).head(noModelSimpleOneHead()).sheet("模板").doWrite(dataList()); + } + + private List> noModelSimpleOneHead() { + List> list = new ArrayList>(); + List head0 = new ArrayList(); + head0.add("表头1"); + list.add(head0); + return list; + } + /** * 不创建对象的写 */ From 937dee76ff8989e5dc1c7e175ceefe71a59ae363 Mon Sep 17 00:00:00 2001 From: JackeyXps <599591947@qq.com> Date: Sat, 17 Apr 2021 17:17:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20issue1702=20=E4=B8=8D=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AF=B9=E8=B1=A1=E7=9A=84=E5=86=99=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/excel/write/executor/ExcelWriteAddExecutor.java | 2 +- .../com/alibaba/easyexcel/test/demo/write/WriteTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 84b9821d..63ed5ce3 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -93,7 +93,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { if (dataIndex >= oneRowData.size()) { return; } - if (headMap.size() != 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 15811fcf..f914f87d 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 @@ -503,14 +503,14 @@ public class WriteTest { } @Test - public void noModelSimpleWriteWithOneHead() { + public void noModelWriteWithOneHead() { // 写法1 String fileName = TestFileUtil.getPath() + "noModelSimpleWrite" + System.currentTimeMillis() + ".xlsx"; // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 - EasyExcel.write(fileName).head(noModelSimpleOneHead()).sheet("模板").doWrite(dataList()); + EasyExcel.write(fileName).head(noModelOneHead()).sheet("模板").doWrite(dataList()); } - private List> noModelSimpleOneHead() { + private List> noModelOneHead() { List> list = new ArrayList>(); List head0 = new ArrayList(); head0.add("表头1");