From 7b9890ae517ac3eb98c80223f8e6713958ddba82 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 5 Nov 2019 19:30:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9Esince?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/excel/write/ExcelBuilderImpl.java | 7 +++++-- .../alibaba/easyexcel/test/demo/write/WriteTest.java | 2 ++ .../easyexcel/test/temp/read/HeadReadTest.java | 12 ++++++++++++ update.md | 4 +++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java index 9658f55..59f78bf 100644 --- a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java +++ b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java @@ -25,10 +25,13 @@ public class ExcelBuilderImpl implements ExcelBuilder { private ExcelWriteFillExecutor excelWriteFillExecutor; private ExcelWriteAddExecutor excelWriteAddExecutor; + static { + // Create temporary cache directory at initialization time to avoid POI concurrent write bugs + FileUtils.createPoiFilesDirectory(); + } + public ExcelBuilderImpl(WriteWorkbook writeWorkbook) { try { - // Create temporary cache directory at initialization time to avoid POI concurrent write bugs - FileUtils.createPoiFilesDirectory(); context = new WriteContextImpl(writeWorkbook); } catch (RuntimeException e) { finishOnException(); 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 3e27bd3..7b7d6b3 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 @@ -73,6 +73,8 @@ public class WriteTest { * 2. 根据自己或者排除自己需要的列 *

* 3. 直接写即可 + * + * @since 2.1.1 */ @Test public void excludeOrIncludeWrite() { diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java index 5127f72..b046d14 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java @@ -8,6 +8,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.cache.Ehcache; /** * 临时测试 @@ -25,4 +26,15 @@ public class HeadReadTest { } + @Test + public void testCache() throws Exception { + File file = new File("D:\\test\\headt1.xls"); + EasyExcel.read(file, HeadReadData.class, new HDListener()).readCache(new Ehcache(20)).sheet(0).doRead(); + + LOGGER.info("------------------"); + EasyExcel.read(file, HeadReadData.class, new HDListener()).readCache(new Ehcache(20)).sheet(0).doRead(); + LOGGER.info("------------------"); + EasyExcel.read(file, HeadReadData.class, new HDListener()).readCache(new Ehcache(20)).sheet(0).doRead(); + } + } diff --git a/update.md b/update.md index 9bd246e..eaaed2b 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,5 @@ +# 2.1.2 + # 2.1.1 * 发布正式版 * 修改map返回为LinkedHashMap @@ -61,7 +63,7 @@ * 修复监听器转换异常会重复提示的bug # 2.0.1 -* 降级poi为3.1.7 兼容jdk6 +* 降级poi为3.17 兼容jdk6 # 2.0.0 * 修复当cell为空可能会抛出空指针的bug From 67e4e10d86a6f3dfe4d647b7b25487c9a30193fd Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 7 Nov 2019 18:49:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=96=B0=E8=A1=8C=E5=A1=AB=E5=85=85=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=80=E8=A1=8C=E6=95=B0=E6=8D=AE=E4=BC=9A?= =?UTF-8?q?=E6=9C=AA=E5=A1=AB=E5=85=85=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../write/executor/ExcelWriteFillExecutor.java | 3 +++ .../easyexcel/test/temp/FillTempTest.java | 17 +++++++++++++---- .../easyexcel/test/temp/fill/FillData2.java | 11 +++++++++++ update.md | 1 + 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java diff --git a/pom.xml b/pom.xml index 7dad24d..c818dd3 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 800b7c0..473d4e3 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 6c82082..8049d89 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 0000000..17c34cf --- /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 eaaed2b..4b6e5a4 100644 --- a/update.md +++ b/update.md @@ -1,4 +1,5 @@ # 2.1.2 +* 修复强制创建新行填充,只有一行数据会未填充的bug # 2.1.1 * 发布正式版