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 981293d3..4696e04c 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -87,15 +87,12 @@ 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; } - if (cellIndex != 0) { - cellIndex++; - } int size = oneRowData.size() - dataIndex; for (int i = 0; i < size; i++) { doAddBasicTypeToExcel(oneRowData, null, row, relativeRowIndex, dataIndex++, 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 new file mode 100644 index 00000000..c2bd7314 --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java @@ -0,0 +1,35 @@ +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 new file mode 100644 index 00000000..66cd1a2f Binary files /dev/null and b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx 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 new file mode 100644 index 00000000..f88b7075 --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java @@ -0,0 +1,47 @@ +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; + } +}