Browse Source

Merge pull request #1880 from SmireG/bugfix

fix #1702
pull/2077/head
Jiaju Zhuang 3 years ago committed by GitHub
parent
commit
8d5db9f256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  2. 35
      src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.java
  3. BIN
      src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx
  4. 47
      src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Issue1702.java

5
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++);

35
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;
}
}

BIN
src/test/java/com/alibaba/easyexcel/test/demo/Test1702/Date1702.xlsx

Binary file not shown.

47
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<Date1702> list = EasyExcelFactory.read(inputStream).head(Date1702.class).sheet(0).doReadSync();
Assert.assertEquals("字符串",list.get(0).getStr());
}
private List<List<String>> head() {
List<List<String>> list = new ArrayList<List<String>>();
List<String> head0 = new ArrayList<String>();
head0.add("表头");
list.add(head0);
return list;
}
private List<List<Object>> dataList() {
List<List<Object>> list = new ArrayList<List<Object>>();
List<Object> data = new ArrayList<Object>();
data.add("字符串");
data.add(new Date());
data.add(0.56);
list.add(data);
return list;
}
}
Loading…
Cancel
Save