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 03607b3d..51d7d3a0 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -85,7 +85,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { public void fill(Object data, FillConfig fillConfig) { if (data == null) { - data = new HashMap(16); + data = new HashMap(16); } if (fillConfig == null) { fillConfig = FillConfig.builder().build(true); @@ -101,7 +101,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { realData = data; currentDataPrefix = null; } - currentUniqueDataFlag = uniqueDataFlag(writeContext.writeSheetHolder().getSheetNo(), currentDataPrefix); + currentUniqueDataFlag = uniqueDataFlag(writeContext.writeSheetHolder(), currentDataPrefix); // processing data if (realData instanceof Collection) { @@ -444,7 +444,6 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { private String dealAnalysisCell(AnalysisCell analysisCell, String value, int rowIndex, int lastPrepareDataIndex, int length, Map> firstRowCache, StringBuilder preparedData) { - Integer sheetNo = writeContext.writeSheetHolder().getSheetNo(); if (analysisCell != null) { if (lastPrepareDataIndex == length) { analysisCell.getPrepareDataList().add(StringUtils.EMPTY); @@ -452,7 +451,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { analysisCell.getPrepareDataList().add(convertPrepareData(value.substring(lastPrepareDataIndex))); analysisCell.setOnlyOneVariable(Boolean.FALSE); } - String uniqueDataFlag = uniqueDataFlag(sheetNo, analysisCell.getPrefix()); + String uniqueDataFlag = uniqueDataFlag(writeContext.writeSheetHolder(), analysisCell.getPrefix()); if (WriteTemplateAnalysisCellTypeEnum.COMMON.equals(analysisCell.getCellType())) { List analysisCellList = templateAnalysisCache.get(uniqueDataFlag); if (analysisCellList == null) { @@ -503,11 +502,17 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { return prepareData; } - private String uniqueDataFlag(Integer sheetNo, String wrapperName) { + private String uniqueDataFlag(WriteSheetHolder writeSheetHolder, String wrapperName) { + String prefix; + if (writeSheetHolder.getSheetNo() != null) { + prefix = writeSheetHolder.getSheetNo().toString(); + } else { + prefix = writeSheetHolder.getSheetName().toString(); + } if (StringUtils.isEmpty(wrapperName)) { - return sheetNo.toString() + "-"; + return prefix + "-"; } - return sheetNo + "-" + wrapperName; + return prefix + "-" + wrapperName; } }