Browse Source

Merge pull request #815 from alibaba/2.1.x

2.1.x
developing
Jiaju Zhuang 5 years ago committed by GitHub
parent
commit
adae8d05c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      pom.xml
  2. 7
      src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
  3. 3
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  4. 2
      src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
  5. 17
      src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
  6. 11
      src/test/java/com/alibaba/easyexcel/test/temp/fill/FillData2.java
  7. 12
      src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
  8. 5
      update.md

2
pom.xml

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

7
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java

@ -25,10 +25,13 @@ public class ExcelBuilderImpl implements ExcelBuilder {
private ExcelWriteFillExecutor excelWriteFillExecutor; private ExcelWriteFillExecutor excelWriteFillExecutor;
private ExcelWriteAddExecutor excelWriteAddExecutor; private ExcelWriteAddExecutor excelWriteAddExecutor;
static {
// Create temporary cache directory at initialization time to avoid POI concurrent write bugs
FileUtils.createPoiFilesDirectory();
}
public ExcelBuilderImpl(WriteWorkbook writeWorkbook) { public ExcelBuilderImpl(WriteWorkbook writeWorkbook) {
try { try {
// Create temporary cache directory at initialization time to avoid POI concurrent write bugs
FileUtils.createPoiFilesDirectory();
context = new WriteContextImpl(writeWorkbook); context = new WriteContextImpl(writeWorkbook);
} catch (RuntimeException e) { } catch (RuntimeException e) {
finishOnException(); finishOnException();

3
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java

@ -127,6 +127,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if (collectionLastIndexMap == null) { if (collectionLastIndexMap == null) {
number--; number--;
} }
if (number <= 0) {
return;
}
sheet.shiftRows(maxRowIndex + 1, lastRowIndex, number, true, false); sheet.shiftRows(maxRowIndex + 1, lastRowIndex, number, true, false);
for (AnalysisCell analysisCell : templateAnalysisCache.get(writeContext.writeSheetHolder().getSheetNo())) { for (AnalysisCell analysisCell : templateAnalysisCache.get(writeContext.writeSheetHolder().getSheetNo())) {
if (analysisCell.getRowIndex() > maxRowIndex) { if (analysisCell.getRowIndex() > maxRowIndex) {

2
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -73,6 +73,8 @@ public class WriteTest {
* 2. 根据自己或者排除自己需要的列 * 2. 根据自己或者排除自己需要的列
* <p> * <p>
* 3. 直接写即可 * 3. 直接写即可
*
* @since 2.1.1
*/ */
@Test @Test
public void excludeOrIncludeWrite() { public void excludeOrIncludeWrite() {

17
src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java

@ -1,6 +1,5 @@
package com.alibaba.easyexcel.test.temp; package com.alibaba.easyexcel.test.temp;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -10,12 +9,12 @@ import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import com.alibaba.easyexcel.test.demo.fill.FillData; 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.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig; import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
/** /**
* 写的填充写法 * 写的填充写法
@ -46,7 +45,7 @@ public class FillTempTest {
// 如果数据量大 list不是最后一行 参照下一个 // 如果数据量大 list不是最后一行 参照下一个
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
excelWriter.fill(data(), fillConfig, writeSheet); excelWriter.fill(data(), fillConfig, writeSheet);
excelWriter.fill(data(), fillConfig, writeSheet); // excelWriter.fill(data2(), fillConfig, writeSheet);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
map.put("date", "2019年10月9日13:28:28"); map.put("date", "2019年10月9日13:28:28");
map.put("total", 1000); map.put("total", 1000);
@ -73,7 +72,7 @@ public class FillTempTest {
WriteSheet writeSheet = EasyExcel.writerSheet().build(); WriteSheet writeSheet = EasyExcel.writerSheet().build();
// 直接写入数据 // 直接写入数据
excelWriter.fill(data(), writeSheet); excelWriter.fill(data(), writeSheet);
excelWriter.fill(data(), writeSheet); excelWriter.fill(data2(), writeSheet);
// 写入list之前的数据 // 写入list之前的数据
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
@ -97,6 +96,16 @@ public class FillTempTest {
// 新建一个 然后一点点复制过来的方案,最后导致list需要新增行的时候,后面的列的数据没法后移,后续会继续想想解决方案 // 新建一个 然后一点点复制过来的方案,最后导致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() { private List<FillData> data() {
List<FillData> list = new ArrayList<FillData>(); List<FillData> list = new ArrayList<FillData>();
for (int i = 0; i < 10; i++) { 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;
}

12
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java

@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.alibaba.excel.EasyExcel; 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();
}
} }

5
update.md

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

Loading…
Cancel
Save