From 6b46e7a47d7fea79d7df0b8be7d246cd3326a1de Mon Sep 17 00:00:00 2001 From: Shaofeng Zhang <11811522@mail.sustech.edu.cn> Date: Sun, 18 Apr 2021 16:00:27 +0800 Subject: [PATCH] fix issue-1663. Skip fill when variable does not exit. --- .../executor/ExcelWriteFillExecutor.java | 5 ++ .../test/temp/issue1663/FillData.java | 9 ++++ .../test/temp/issue1663/FillTest.java | 47 ++++++++++++++++++ src/test/resources/issue1663/template.xlsx | Bin 0 -> 10025 bytes 4 files changed, 61 insertions(+) create mode 100644 src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillData.java create mode 100644 src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java create mode 100644 src/test/resources/issue1663/template.xlsx 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 5930a311..df0fe70e 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -188,6 +188,11 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder(); Map fieldNameContentPropertyMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getFieldNameContentPropertyMap(); + + if (analysisCellList == null ){ + return; + } + for (AnalysisCell analysisCell : analysisCellList) { Cell cell = getOneCell(analysisCell, fillConfig); if (analysisCell.getOnlyOneVariable()) { diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillData.java b/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillData.java new file mode 100644 index 00000000..57b54107 --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillData.java @@ -0,0 +1,9 @@ +package com.alibaba.easyexcel.test.temp.issue1663; + +import lombok.Data; + +@Data +public class FillData { + private String name; + private double number; +} diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java new file mode 100644 index 00000000..ddcdf45a --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java @@ -0,0 +1,47 @@ +package com.alibaba.easyexcel.test.temp.issue1663; + +import com.alibaba.easyexcel.test.demo.fill.FillData; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.enums.WriteDirectionEnum; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.metadata.fill.FillConfig; +import com.alibaba.excel.write.metadata.fill.FillWrapper; +import org.junit.Test; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FillTest { + @Test + public void TestFillNullPoint(){ + String templateFileName = + TestFileUtil.getPath() + "issue1663" + File.separator + "template.xlsx"; + + String fileName = TestFileUtil.getPath() + "issue1663" + File.separator + "issue1663.xlsx"; + ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); + WriteSheet writeSheet = EasyExcel.writerSheet().build(); + FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); + excelWriter.fill(new FillWrapper("data1", data()), fillConfig, writeSheet); + + Map map = new HashMap(); + // Variable {date} does not exist in the template.xlsx, which should be ignored instead of reporting an error. + map.put("date", "2019年10月9日13:28:28"); + excelWriter.fill(map, writeSheet); + excelWriter.finish(); + } + private List data() { + List list = new ArrayList(); + for (int i = 0; i < 10; i++) { + com.alibaba.easyexcel.test.demo.fill.FillData fillData = new FillData(); + list.add(fillData); + fillData.setName("张三"); + fillData.setNumber(5.2); + } + return list; + } +} diff --git a/src/test/resources/issue1663/template.xlsx b/src/test/resources/issue1663/template.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..a968ff4151813d9eec2a251185b4f7dda603c4c5 GIT binary patch literal 10025 zcme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