diff --git a/pom.xml b/pom.xml index 7dad24da..c818dd34 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 2.1.1 + 2.1.2 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java index 800b7c07..473d4e34 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -127,6 +127,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { if (collectionLastIndexMap == null) { number--; } + if (number <= 0) { + return; + } sheet.shiftRows(maxRowIndex + 1, lastRowIndex, number, true, false); for (AnalysisCell analysisCell : templateAnalysisCache.get(writeContext.writeSheetHolder().getSheetNo())) { if (analysisCell.getRowIndex() > maxRowIndex) { diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java index 6c82082d..8049d89c 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java @@ -1,6 +1,5 @@ package com.alibaba.easyexcel.test.temp; -import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -10,12 +9,12 @@ import org.junit.Ignore; import org.junit.Test; import com.alibaba.easyexcel.test.demo.fill.FillData; +import com.alibaba.easyexcel.test.temp.fill.FillData2; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.fill.FillConfig; -import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy; /** * 写的填充写法 @@ -46,7 +45,7 @@ public class FillTempTest { // 如果数据量大 list不是最后一行 参照下一个 FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(data(), fillConfig, writeSheet); - excelWriter.fill(data(), fillConfig, writeSheet); +// excelWriter.fill(data2(), fillConfig, writeSheet); Map map = new HashMap(); map.put("date", "2019年10月9日13:28:28"); map.put("total", 1000); @@ -73,7 +72,7 @@ public class FillTempTest { WriteSheet writeSheet = EasyExcel.writerSheet().build(); // 直接写入数据 excelWriter.fill(data(), writeSheet); - excelWriter.fill(data(), writeSheet); + excelWriter.fill(data2(), writeSheet); // 写入list之前的数据 Map map = new HashMap(); @@ -97,6 +96,16 @@ public class FillTempTest { // 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案 } + private List data2() { + List list = new ArrayList(); + for (int i = 0; i < 10; i++) { + FillData2 fillData = new FillData2(); + list.add(fillData); + fillData.setTest("ttttttt" + i); + } + return list; + } + private List data() { List list = new ArrayList(); for (int i = 0; i < 10; i++) { diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java b/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java new file mode 100644 index 00000000..17c34cf1 --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java @@ -0,0 +1,11 @@ +package com.alibaba.easyexcel.test.temp.fill; + +import lombok.Data; + +/** + * @author Jiaju Zhuang + */ +@Data +public class FillData2 { + private String test; +} diff --git a/update.md b/update.md index eaaed2bf..4b6e5a49 100644 --- a/update.md +++ b/update.md @@ -1,4 +1,5 @@ # 2.1.2 +* 修复强制创建新行填充,只有一行数据会未填充的bug # 2.1.1 * 发布正式版