|
|
@ -7,6 +7,9 @@ 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_TAG; |
|
|
|
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TYPE_TAG; |
|
|
|
import static com.alibaba.excel.constant.ExcelXmlConstants.CELL_VALUE_TYPE_TAG; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
import java.util.Deque; |
|
|
|
|
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.TreeMap; |
|
|
|
import java.util.TreeMap; |
|
|
|
|
|
|
|
|
|
|
@ -33,8 +36,7 @@ import com.alibaba.excel.util.StringUtils; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder { |
|
|
|
public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder { |
|
|
|
private final AnalysisContext analysisContext; |
|
|
|
private final AnalysisContext analysisContext; |
|
|
|
private String currentTag; |
|
|
|
private Deque<String> currentTagDeque = new LinkedList<String>(); |
|
|
|
private String currentCellIndex; |
|
|
|
|
|
|
|
private int curCol; |
|
|
|
private int curCol; |
|
|
|
private Map<Integer, CellData> curRowContent = new TreeMap<Integer, CellData>(); |
|
|
|
private Map<Integer, CellData> curRowContent = new TreeMap<Integer, CellData>(); |
|
|
|
private CellData currentCellData; |
|
|
|
private CellData currentCellData; |
|
|
@ -61,11 +63,10 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void startHandle(String name, Attributes attributes) { |
|
|
|
public void startHandle(String name, Attributes attributes) { |
|
|
|
currentTag = name; |
|
|
|
currentTagDeque.push(name); |
|
|
|
// start a cell
|
|
|
|
// start a cell
|
|
|
|
if (CELL_TAG.equals(name)) { |
|
|
|
if (CELL_TAG.equals(name)) { |
|
|
|
currentCellIndex = attributes.getValue(ExcelXmlConstants.POSITION); |
|
|
|
curCol = PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.POSITION)); |
|
|
|
curCol = PositionUtils.getCol(currentCellIndex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// t="s" ,it's means String
|
|
|
|
// t="s" ,it's means String
|
|
|
|
// t="str" ,it's means String,but does not need to be read in the 'sharedStrings.xml'
|
|
|
|
// t="str" ,it's means String,but does not need to be read in the 'sharedStrings.xml'
|
|
|
@ -100,6 +101,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void endHandle(String name) { |
|
|
|
public void endHandle(String name) { |
|
|
|
|
|
|
|
currentTagDeque.pop(); |
|
|
|
if (CELL_VALUE_TAG.equals(name)) { |
|
|
|
if (CELL_VALUE_TAG.equals(name)) { |
|
|
|
// Have to go "sharedStrings.xml" and get it
|
|
|
|
// Have to go "sharedStrings.xml" and get it
|
|
|
|
if (currentCellData.getType() == CellDataTypeEnum.STRING) { |
|
|
|
if (currentCellData.getType() == CellDataTypeEnum.STRING) { |
|
|
@ -133,6 +135,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
if (StringUtils.isEmpty(currentCellValue)) { |
|
|
|
if (StringUtils.isEmpty(currentCellValue)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String currentTag = currentTagDeque.peek(); |
|
|
|
if (currentTag == null) { |
|
|
|
if (currentTag == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -162,8 +165,8 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
case NUMBER: |
|
|
|
case NUMBER: |
|
|
|
case EMPTY: |
|
|
|
case EMPTY: |
|
|
|
currentCellData.setType(CellDataTypeEnum.NUMBER); |
|
|
|
currentCellData.setType(CellDataTypeEnum.NUMBER); |
|
|
|
if (currentCellData.getDoubleValue() == null) { |
|
|
|
if (currentCellData.getNumberValue() == null) { |
|
|
|
currentCellData.setDoubleValue(Double.valueOf(currentCellValue)); |
|
|
|
currentCellData.setNumberValue(new BigDecimal(currentCellValue)); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|