Browse Source

修复强制创建新行填充,只有一行数据会未填充的bug

pull/815/head 2.1.2
Jiaju Zhuang 5 years ago
parent
commit
67e4e10d86
  1. 2
      pom.xml
  2. 3
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  3. 17
      src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
  4. 11
      src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java
  5. 1
      update.md

2
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.1</version>
<version>2.1.2</version>
<packaging>jar</packaging>
<name>easyexcel</name>

3
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) {

17
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<String, Object> map = new HashMap<String, Object>();
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<String, Object> map = new HashMap<String, Object>();
@ -97,6 +96,16 @@ public class FillTempTest {
// 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案
}
private List<FillData2> data2() {
List<FillData2> list = new ArrayList<FillData2>();
for (int i = 0; i < 10; i++) {
FillData2 fillData = new FillData2();
list.add(fillData);
fillData.setTest("ttttttt" + i);
}
return list;
}
private List<FillData> data() {
List<FillData> list = new ArrayList<FillData>();
for (int i = 0; i < 10; i++) {

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

1
update.md

@ -1,4 +1,5 @@
# 2.1.2
* 修复强制创建新行填充,只有一行数据会未填充的bug
# 2.1.1
* 发布正式版

Loading…
Cancel
Save