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/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/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/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/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/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..4b6e5a4 100644
--- a/update.md
+++ b/update.md
@@ -1,3 +1,6 @@
+# 2.1.2
+* 修复强制创建新行填充,只有一行数据会未填充的bug
+
# 2.1.1
* 发布正式版
* 修改map返回为LinkedHashMap
@@ -61,7 +64,7 @@
* 修复监听器转换异常会重复提示的bug
# 2.0.1
-* 降级poi为3.1.7 兼容jdk6
+* 降级poi为3.17 兼容jdk6
# 2.0.0
* 修复当cell为空可能会抛出空指针的bug