From 1802500088c2d2ed70f6c1170be1d4de5c5d40be Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 16 Sep 2019 18:32:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93cell=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=8F=AF=E8=83=BD=E4=BC=9A=E6=8A=9B=E5=87=BA=E7=A9=BA?= =?UTF-8?q?=E6=8C=87=E9=92=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../analysis/v07/handlers/DefaultCellHandler.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java index 37d12ad7..8d4eb703 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java @@ -7,6 +7,8 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_TAG; import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TAG; import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TYPE_TAG; +import java.util.Deque; +import java.util.LinkedList; import java.util.Map; import java.util.TreeMap; @@ -33,8 +35,7 @@ import com.alibaba.excel.util.StringUtils; */ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder { private final AnalysisContext analysisContext; - private String currentTag; - private String currentCellIndex; + private Deque currentTagDeque = new LinkedList(); private int curCol; private Map curRowContent = new TreeMap(); private CellData currentCellData; @@ -61,11 +62,10 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder @Override public void startHandle(String name, Attributes attributes) { - currentTag = name; + currentTagDeque.push(name); // start a cell if (CELL_TAG.equals(name)) { - currentCellIndex = attributes.getValue(ExcelXmlConstants.POSITION); - curCol = PositionUtils.getCol(currentCellIndex); + curCol = PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.POSITION)); // t="s" ,it's means String // t="str" ,it's means String,but does not need to be read in the 'sharedStrings.xml' @@ -100,6 +100,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder @Override public void endHandle(String name) { + currentTagDeque.pop(); if (CELL_VALUE_TAG.equals(name)) { // Have to go "sharedStrings.xml" and get it if (currentCellData.getType() == CellDataTypeEnum.STRING) { @@ -133,6 +134,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder if (StringUtils.isEmpty(currentCellValue)) { return; } + String currentTag = currentTagDeque.peek(); if (currentTag == null) { return; }