From 41d1220c01d1b2fdb7534bd92e0b9381c16b6e7b Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 16 Sep 2021 16:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=86=99=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=20[Issue=20#1702]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../write/executor/ExcelWriteAddExecutor.java | 4 +- .../test/demo/Test1702/Date1702.java | 35 ------------- .../test/demo/Test1702/Date1702.xlsx | Bin 3557 -> 0 bytes .../test/demo/Test1702/Issue1702.java | 47 ------------------ .../easyexcel/test/demo/write/WriteTest.java | 16 ------ .../easyexcel/test/temp/Lock2Test.java | 6 +-- update.md | 1 + 7 files changed, 5 insertions(+), 104 deletions(-) delete mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java delete mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx delete mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java 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 66cd1a2f361b792492007e460b335908f3aa95af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3557 zcmaJ@c|25Y8>Yd`kdP%?*;RP6h9a^yvP;>@Hiogzf-;t|HX;UDix!ORh3rh4RI(&X zA~MO6tz^we^3CY`US8i@_xYVO=Z|wgbKloAetY$lN;{e8<7Klw>BUUpmC~X?ld=P3ONd45^cuTgyewpd{RjHIZ~oL zfJjJvfBiuCo-`ci^TBCVV2bT0`@@xD-v}z+LB&g^Oj(M3-Fz?4)G+x!eV@#mad@K> z6YO*-GqyB7LAMD!@n9)!pO*tb&*tUh3_9ZHinYrqFCoQ#W25ON7@Q{-|6Zz(p>4GA zqGG*`Tt(J2;%t9H4gh?T>qm|~X!?=RK*%05Lm((WE|54z?c87w9i7>4vEihCVW)%e z@q_vJIap$lFyBkZ0=&Jd&b9kIm1F;r`m$e2dD-kd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&qHm2{uR1}rYkz3nFzlV!%+mY|| zqclhU&)DJ5%?$sUxYJD0?CN$1Qvd2-% 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