From ef4184d52023d1feb208cfd54b783dc042d4a7c9 Mon Sep 17 00:00:00 2001 From: yizhi Date: Tue, 27 Jul 2021 20:12:00 +0800 Subject: [PATCH] fix issue-2014 --- .../excel/read/listener/ModelBuildEventListener.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java index 78b57e0a..8ac2ea22 100644 --- a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java @@ -26,9 +26,12 @@ import net.sf.cglib.beans.BeanMap; * @author jipengfei */ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener> { + private int headSize; @Override - public void invokeHead(Map cellDataMap, AnalysisContext context) {} + public void invokeHead(Map cellDataMap, AnalysisContext context) { + this.headSize = cellDataMap.size(); + } @Override public void invoke(Map cellDataMap, AnalysisContext context) { @@ -62,7 +65,8 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener (String)ConverterUtils.convertToJavaObject(cellData, null, null, currentReadHolder.converterMap(), currentReadHolder.globalConfiguration(), context.readRowHolder().getRowIndex(), key)); } - int headSize = currentReadHolder.excelReadHeadProperty().getHeadMap().size(); + int headSize = currentReadHolder.excelReadHeadProperty().getHeadMap().size() == 0 + ? this.headSize : currentReadHolder.excelReadHeadProperty().getHeadMap().size(); while (index < headSize) { map.put(index, null); index++; @@ -87,7 +91,8 @@ public class ModelBuildEventListener extends AbstractIgnoreExceptionReadListener (String)ConverterUtils.convertToJavaObject(cellData, null, null, currentReadHolder.converterMap(), currentReadHolder.globalConfiguration(), context.readRowHolder().getRowIndex(), key)); } - int headSize = currentReadHolder.excelReadHeadProperty().getHeadMap().size(); + int headSize = currentReadHolder.excelReadHeadProperty().getHeadMap().size() == 0 + ? this.headSize : currentReadHolder.excelReadHeadProperty().getHeadMap().size(); while (index < headSize) { list.add(null); index++;