From d797accc83beba5d64d2ceed9506e2bf40f3b98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=B9=8F=E4=BD=B3?= <532332729@qq.com> Date: Tue, 27 Oct 2020 13:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A0=E5=8F=98=E9=87=8Fnp?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/ExcelWriteFillExecutor.java | 3 +++ .../easyexcel/test/demo/fill/FillTest.java | 18 ++++++++++++++++++ src/test/resources/demo/fill/no_variable.xlsx | Bin 0 -> 9946 bytes 3 files changed, 21 insertions(+) create mode 100644 src/test/resources/demo/fill/no_variable.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..4bfd06fc 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,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder(); Map fieldNameContentPropertyMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getFieldNameContentPropertyMap(); + if(null == analysisCellList || analysisCellList.isEmpty()){ + return; + } for (AnalysisCell analysisCell : analysisCellList) { Cell cell = getOneCell(analysisCell, fillConfig); if (analysisCell.getOnlyOneVariable()) { diff --git a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java index 7a0e92e5..3c77ba78 100644 --- a/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java @@ -80,6 +80,24 @@ public class FillTest { excelWriter.finish(); } + /** + * 处理无变量问题 + * + * @since 2.1.1 + */ + @Test + public void noVariableFill() { + // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 + // 填充list 的时候还要注意 模板中{.} 多了个点 表示list + String templateFileName = + TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "no_variable.xlsx"; + + // 方案1 一下子全部放到内存里面 并填充 + String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; + // 这里 会填充到第一个sheet, 然后文件流会自动关闭 + EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(data()); + } + /** * 复杂的填充 * diff --git a/src/test/resources/demo/fill/no_variable.xlsx b/src/test/resources/demo/fill/no_variable.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..982321d6e39412eef856e1691fe579c303e0324f GIT binary patch literal 9946 zcmeHtbyO7G);CD^P=a(fNDI>4Fm$&ALw5;7hayM`(hbtm-5sKYAl)e-p>(~2zW4Ew z``o+Uf4{Z9vlcTf*m2I@`|Q2f`E8&A96Tz_-3n7)5xx8V*Fu5*^31^;=<-^olJ9oanXY|~5H+LQVts0hRB!qh7p8!V~L> z)G2R_N)oU$p+jl-l69;*R}b)k({7Cnj54)&;KtPGj83kX0Vhh{T?ttcHoyz-TajbJY0n34am^=XFz5)SN zXV8`>5_MrD<_)oe!}yY5 zOhk;8`7|J&;u_IwS0n#g6vB6$j9rr0S!gzBp%vH!(N3$H!9|^NWnA{fIq55buM~t4 zc5%l#9_g?(tb5YBzM6bNl!sSZSwCjQ8vQ^5^$~*&`!U0f1?$#_E3Yi&+J2Ub@7c+P zg-v@2W~8-0KG3l0B;;u$xCuA#&8VpkNaVQvbfv!bwryDov_%TkfdL{5KgHH^{Jg!X?1tLxe zDK{w>fWz1I_!dg>ev!gXj850z5)mWRq?`16BPq(fZ?CS;(EfD7%X}Es8>sPpp^m`) z!wGIKt`2rT13p^FA&4CydMba7mEd8%8j1q|;L9dpmVV|Is8ljTneFGTF8J#AU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