Browse Source

Merge pull request #1631 from chenpengjia006/developing

修复 模板没有变量的时候报错 #1564
pull/2074/head
Jiaju Zhuang 4 years ago committed by GitHub
parent
commit
28c72d6db9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  2. 18
      src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java
  3. BIN
      src/test/resources/demo/fill/no_variable.xlsx

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

@ -188,6 +188,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder(); WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
Map<String, ExcelContentProperty> fieldNameContentPropertyMap = Map<String, ExcelContentProperty> fieldNameContentPropertyMap =
writeContext.currentWriteHolder().excelWriteHeadProperty().getFieldNameContentPropertyMap(); writeContext.currentWriteHolder().excelWriteHeadProperty().getFieldNameContentPropertyMap();
if(null == analysisCellList || analysisCellList.isEmpty()){
return;
}
for (AnalysisCell analysisCell : analysisCellList) { for (AnalysisCell analysisCell : analysisCellList) {
Cell cell = getOneCell(analysisCell, fillConfig); Cell cell = getOneCell(analysisCell, fillConfig);
if (analysisCell.getOnlyOneVariable()) { if (analysisCell.getOnlyOneVariable()) {

18
src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java

@ -80,6 +80,24 @@ public class FillTest {
excelWriter.finish(); 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());
}
/** /**
* 复杂的填充 * 复杂的填充
* *

BIN
src/test/resources/demo/fill/no_variable.xlsx

Binary file not shown.
Loading…
Cancel
Save