From 6407a8abcaa50c16bb9b9306590523a08a2c0cf7 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Tue, 14 Sep 2021 21:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A1=AB=E5=85=85=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=A1=AB=E5=85=85=E9=94=99=E8=AF=AF=E7=9A=84bug=20#20?= =?UTF-8?q?35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../write/executor/ExcelWriteFillExecutor.java | 16 +++++++--------- update.md | 1 + 2 files changed, 8 insertions(+), 9 deletions(-) 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 e15a96c9..5e6139f6 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -199,7 +199,8 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { continue; } Object value = dataMap.get(variable); - WriteCellData cellData = converterAndSet(writeSheetHolder, FieldUtils.getFieldClass(dataMap, variable), + WriteCellData cellData = converterAndSet(writeSheetHolder, + FieldUtils.getFieldClass(dataMap, variable), null, cell, value, fieldNameContentPropertyMap.get(variable), null, relativeRowIndex); WriteHandlerUtils.afterCellDispose(writeContext, cellData, cell, null, relativeRowIndex, Boolean.FALSE); } else { @@ -416,7 +417,6 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { int startIndex = 0; int length = value.length(); int lastPrepareDataIndex = 0; - int variableCount = 0; out: while (startIndex < length) { int prefixIndex = value.indexOf(FILL_PREFIX, startIndex); @@ -448,10 +448,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { String variable = value.substring(prefixIndex + 1, suffixIndex); if (StringUtils.isEmpty(variable)) { continue; - } else { - ++variableCount; } - int collectPrefixIndex = variable.indexOf(COLLECTION_PREFIX); if (collectPrefixIndex > -1) { if (collectPrefixIndex != 0) { @@ -466,18 +463,19 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { analysisCell.getVariableList().add(variable); if (lastPrepareDataIndex == prefixIndex) { analysisCell.getPrepareDataList().add(StringUtils.EMPTY); + // fix https://github.com/alibaba/easyexcel/issues/2035 + if (lastPrepareDataIndex != 0) { + analysisCell.setOnlyOneVariable(Boolean.FALSE); + } } else { String data = convertPrepareData(value.substring(lastPrepareDataIndex, prefixIndex)); preparedData.append(data); analysisCell.getPrepareDataList().add(data); + analysisCell.setOnlyOneVariable(Boolean.FALSE); } lastPrepareDataIndex = suffixIndex + 1; } - if (variableCount > 1) { - analysisCell.setOnlyOneVariable(Boolean.FALSE); - } - return dealAnalysisCell(analysisCell, value, rowIndex, lastPrepareDataIndex, length, firstRowCache, preparedData); } diff --git a/update.md b/update.md index a6a8208d..23aef9c6 100644 --- a/update.md +++ b/update.md @@ -16,6 +16,7 @@ * 写入支持Collection [Issue #1834](https://github.com/alibaba/easyexcel/issues/1834) * `Converter`支持null转换 [Issue #1776](https://github.com/alibaba/easyexcel/issues/1776) * cglib 新增命名策略,防止和`spring`的冲突 [Issue #2064](https://github.com/alibaba/easyexcel/issues/2064) +* 修改填充可能填充错误的bug [Issue #2035](https://github.com/alibaba/easyexcel/issues/2035) # 2.2.10 * 修复读取的时候用string接收数字 可能四舍五入不一致的bug