Browse Source

修改合并异常

2.1.x
Jiaju Zhuang 5 years ago
parent
commit
0bf3e5e9a5
  1. 19
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java

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

Loading…
Cancel
Save