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 c634b79c..cd1a6f4e 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -92,12 +92,14 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } cellIndex = entry.getKey(); Head head = entry.getValue(); - doAddBasicTypeToExcel(oneRowData, head, row, relativeRowIndex, dataIndex++, cellIndex++); + doAddBasicTypeToExcel(oneRowData, head, row, relativeRowIndex, dataIndex++, cellIndex); } // Finish if (dataIndex >= oneRowData.size()) { return; } + // fix https://github.com/alibaba/easyexcel/issues/1702 + // If there is data, it is written to the next cell if (dataIndex != 0) { cellIndex++; } diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java deleted file mode 100644 index c2bd7314..00000000 --- a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.alibaba.easyexcel.test.demo.Test1702; - -import com.alibaba.excel.annotation.ExcelProperty; - -import java.util.Date; - -public class Date1702 { - @ExcelProperty(index = 0) - private String str; - @ExcelProperty(index = 1) - private Date date; - @ExcelProperty(index = 2) - private double r; - public void setStr(String str) { - this.str = str; - } - public void setDate(Date date) { - this.date = date; - } - public void setR(double r) { - this.r = r; - } - - public String getStr() { - return str; - } - - public Date getDate(){ - return date; - } - public double getR(){ - return r; - } -} - diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx deleted file mode 100644 index 66cd1a2f..00000000 Binary files a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx and /dev/null differ diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java deleted file mode 100644 index f88b7075..00000000 --- a/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.alibaba.easyexcel.test.demo.Test1702; - -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 Issue1702 { - @Test - public void test1702() throws FileNotFoundException { - -// String fileName = TestFileUtil.getPath() + "TestIssue" + File.separator + "Date1702.xlsx"; - String fileName = "src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx"; - EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList()); - InputStream inputStream = new FileInputStream(fileName); - List list = EasyExcelFactory.read(inputStream).head(Date1702.class).sheet(0).doReadSync(); - Assert.assertEquals("字符串",list.get(0).getStr()); - } - - - private List> head() { - List> list = new ArrayList>(); - List head0 = new ArrayList(); - head0.add("表头"); - list.add(head0); - return list; - } - - private List> dataList() { - List> list = new ArrayList>(); - List data = new ArrayList(); - data.add("字符串"); - data.add(new Date()); - data.add(0.56); - list.add(data); - return list; - } -} 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 ec124a43..1bf11fe4 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,22 +601,6 @@ 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; - } - /** * 不创建对象的写 */ diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java index e722344d..88e3211f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java @@ -95,10 +95,6 @@ public class Lock2Test { head0.add("表头"); list.add(head0); - List head1 = new ArrayList(); - head1.add("表头2"); - - list.add(head1); return list; } @@ -107,7 +103,7 @@ public class Lock2Test { List data = new ArrayList(); data.add("字符串"); data.add(new Date()); - //data.add(0.56); + data.add(0.56); list.add(data); return list; } diff --git a/update.md b/update.md index 8e976243..db002b67 100644 --- a/update.md +++ b/update.md @@ -23,6 +23,7 @@ * 修复不自动行高的问题 [Issue #1869](https://github.com/alibaba/easyexcel/issues/1869) * 新增头的非空校验 [Issue #1765](https://github.com/alibaba/easyexcel/issues/1765) * 修复某些特殊的excel读取失败的问题 [Issue #1595](https://github.com/alibaba/easyexcel/issues/1595) +* 修复不创建对象写入数据异常 [Issue #1702](https://github.com/alibaba/easyexcel/issues/1702) # 2.2.10