From ec77c3e7400003f3be1a6e0d61f2689e74106426 Mon Sep 17 00:00:00 2001 From: smireg <402809775@qq.com> Date: Sun, 18 Apr 2021 00:15:58 +0800 Subject: [PATCH] fix #1702 --- .../write/executor/ExcelWriteAddExecutor.java | 5 +- .../test/demo/Test1702/Date1702.java | 35 +++++++++++++ .../test/demo/Test1702/Date1702.xlsx | Bin 0 -> 3557 bytes .../test/demo/Test1702/Issue1702.java | 47 ++++++++++++++++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java create mode 100644 src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx create 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 9f229029..e75b333e 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 0000000000000000000000000000000000000000..66cd1a2f361b792492007e460b335908f3aa95af GIT binary patch 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-kdcesvF3s2!P;9^j+HAUiK_WbH4 zplXUm3^QsG>gwid_06RkRc))I%^BSMBKVoqycB$_0T&`;KNEDpDb3zcKwYT=sGMoS zGX%0WFKofBoM-`xn5~S6FS3(3dvN0}_n|YoDIQ1F*lTjTZ<~?a=Ic83B8?B5cD1Fx z>KmJT3{f$90gu0N(;}v-|4hz`ed6IV05FJi0S77xBqz2#5YSGFQ53|pwBMW|!;iJX zDOQzT)%xN4JSGaFbjySjd0h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L9FYKK{ujq$v{Kl#Lf+wooM%E|}z zO^>y?pz<@$2O@FK*{2=L%27_mA7LAQ{%q~v7jsVP4thJkkLduu?aEV1v8edcC1C%I zUdLw;LM8~hOJjtUSg%}bU0t*-RGW@xK`Ny9;l-*;A5nO}WVR%l?0-roG^VMk$h~Q5 zzhj^z>9laq=Xm9PHwGIk=+eymlh6^~tL3dBj#Of>dUA)33pQya2z?MP z@QY`%J+2~rADar5=li61BGhtoOH&nj?G`4e{oDUh5BPr}^vl2O#OarpNiz1NdYRLk zvE3o49ujY^k1Vun_U#58R2l^rT z2{YowSohhlnyRci>Ymcml+Ok@5BR)&t%@nt6pyzt(o0l@6s?hL!C*I8RyRWZbX|x2 z?4!NP>&SV);Q1l)J9KB5MDORE$cpO+Gl;T)B7nhT$KY;@c0%Du{Ylp!32E!ty_A<9 zz4d!oE;ocl5(OWfyxu())&G!k|7Tv)MqeoM1VsDIIn2S~Dnl$oK5s+qw@)lI!NCF4 zlHO1|SNx-S;oWABFB}H*^QFor^+%pYBYz8$&yd_+B5+C*B-LdnYGb0HQgx|PAmWRe zqjfczJG1)g;0+P^R*le<2Ibl6Lk#mVfe8tO#i6@8ukj<1sOphcZ8TFgx~klp6dL@Y zQxR)t-?5myWSR{)t6p&3o`149 zqj1Sy8sqCHo!BU409J?DNaPdr^xx(Z)mA^FasBKgHe5dYaC zmt*Nm;!q2p8-B?$n>w2mql6&UG<3P`MPfL?s3a#l&E@U z>CAKFW%*Z5S#{||_DXmDSZd7Y9j0Uo^sjus+vY&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; + } +}