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 217f21e5..555f29be 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -279,7 +279,12 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { if (cell == null) { continue; } - prepareData(cell.getStringCellValue(), analysisCellList, collectionAnalysisCellList, i, j); + boolean needFill = + prepareData(cell.getStringCellValue(), analysisCellList, collectionAnalysisCellList, i, j); + // Prevent empty data from not being replaced + if (needFill) { + cell.setCellValue(StringUtils.EMPTY); + } } } templateAnalysisCache.put(sheetNo, analysisCellList); @@ -287,10 +292,19 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { return analysisCache.get(sheetNo); } - private void prepareData(String value, List analysisCellList, + /** + * + * @param value + * @param analysisCellList + * @param collectionAnalysisCellList + * @param rowIndex + * @param columnIndex + * @return Is a cell to be filled + */ + private boolean prepareData(String value, List analysisCellList, List collectionAnalysisCellList, int rowIndex, int columnIndex) { if (StringUtils.isEmpty(value)) { - return; + return false; } AnalysisCell analysisCell = null; int startIndex = 0; @@ -365,7 +379,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { } else { collectionAnalysisCellList.add(analysisCell); } + return true; } + return false; } private String convertPrepareData(String prepareData) { diff --git a/update.md b/update.md index 9bbd87ab..f1f5cf86 100644 --- a/update.md +++ b/update.md @@ -1,6 +1,6 @@ # 2.1.0-beta2 * 修改模板通过流创建报错的bug -* +* 修复空数据未替换掉的bug # 2.1.0-beta1 * 新增支持导入、导出支持公式