|
|
@ -40,6 +40,9 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
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; |
|
|
|
|
|
|
|
private StringBuilder dataStringBuilder; |
|
|
|
|
|
|
|
private StringBuilder formulaStringBuilder; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Current style information |
|
|
|
* Current style information |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -77,6 +80,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
// t is null ,it's means Empty or Number
|
|
|
|
// t is null ,it's means Empty or Number
|
|
|
|
CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(attributes.getValue(CELL_VALUE_TYPE_TAG)); |
|
|
|
CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(attributes.getValue(CELL_VALUE_TYPE_TAG)); |
|
|
|
currentCellData = new CellData(type); |
|
|
|
currentCellData = new CellData(type); |
|
|
|
|
|
|
|
dataStringBuilder = new StringBuilder(); |
|
|
|
|
|
|
|
|
|
|
|
// Put in data transformation information
|
|
|
|
// Put in data transformation information
|
|
|
|
String dateFormatIndex = attributes.getValue(CELL_DATA_FORMAT_TAG); |
|
|
|
String dateFormatIndex = attributes.getValue(CELL_DATA_FORMAT_TAG); |
|
|
@ -96,26 +100,50 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
// cell is formula
|
|
|
|
// cell is formula
|
|
|
|
if (CELL_FORMULA_TAG.equals(name)) { |
|
|
|
if (CELL_FORMULA_TAG.equals(name)) { |
|
|
|
currentCellData.setFormula(Boolean.TRUE); |
|
|
|
currentCellData.setFormula(Boolean.TRUE); |
|
|
|
|
|
|
|
formulaStringBuilder = new StringBuilder(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void endHandle(String name) { |
|
|
|
public void endHandle(String name) { |
|
|
|
currentTagDeque.pop(); |
|
|
|
// cell is formula
|
|
|
|
|
|
|
|
if (CELL_FORMULA_TAG.equals(name)) { |
|
|
|
|
|
|
|
currentCellData.setFormulaValue(formulaStringBuilder.toString()); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (CELL_VALUE_TAG.equals(name) || CELL_INLINE_STRING_VALUE_TAG.equals(name)) { |
|
|
|
|
|
|
|
CellDataTypeEnum oldType = currentCellData.getType(); |
|
|
|
|
|
|
|
switch (oldType) { |
|
|
|
|
|
|
|
case DIRECT_STRING: |
|
|
|
|
|
|
|
case STRING: |
|
|
|
|
|
|
|
case ERROR: |
|
|
|
|
|
|
|
currentCellData.setStringValue(dataStringBuilder.toString()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case BOOLEAN: |
|
|
|
|
|
|
|
currentCellData.setBooleanValue(BooleanUtils.valueOf(dataStringBuilder.toString())); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case NUMBER: |
|
|
|
|
|
|
|
case EMPTY: |
|
|
|
|
|
|
|
currentCellData.setType(CellDataTypeEnum.NUMBER); |
|
|
|
|
|
|
|
currentCellData.setNumberValue(new BigDecimal(dataStringBuilder.toString())); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new IllegalStateException("Cannot set values now"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
String stringValue = analysisContext.readWorkbookHolder().getReadCache() |
|
|
|
String stringValue = analysisContext.readWorkbookHolder().getReadCache() |
|
|
|
.get(Integer.valueOf(currentCellData.getStringValue())); |
|
|
|
.get(Integer.valueOf(currentCellData.getStringValue())); |
|
|
|
if (stringValue != null && analysisContext.currentReadHolder().globalConfiguration().getAutoTrim()) { |
|
|
|
if (stringValue != null |
|
|
|
|
|
|
|
&& analysisContext.currentReadHolder().globalConfiguration().getAutoTrim()) { |
|
|
|
stringValue = stringValue.trim(); |
|
|
|
stringValue = stringValue.trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
currentCellData.setStringValue(stringValue); |
|
|
|
currentCellData.setStringValue(stringValue); |
|
|
|
} else if (currentCellData.getType() == CellDataTypeEnum.DIRECT_STRING) { |
|
|
|
} else if (currentCellData.getType() == CellDataTypeEnum.DIRECT_STRING) { |
|
|
|
currentCellData.setType(CellDataTypeEnum.STRING); |
|
|
|
currentCellData.setType(CellDataTypeEnum.STRING); |
|
|
|
} |
|
|
|
} |
|
|
|
currentCellData.checkEmpty(); |
|
|
|
|
|
|
|
curRowContent.put(curCol, currentCellData); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// This is a special form of string
|
|
|
|
// This is a special form of string
|
|
|
|
if (CELL_INLINE_STRING_VALUE_TAG.equals(name)) { |
|
|
|
if (CELL_INLINE_STRING_VALUE_TAG.equals(name)) { |
|
|
@ -125,53 +153,28 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder |
|
|
|
stringValue = stringValue.trim(); |
|
|
|
stringValue = stringValue.trim(); |
|
|
|
} |
|
|
|
} |
|
|
|
currentCellData.setStringValue(stringValue); |
|
|
|
currentCellData.setStringValue(stringValue); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
currentCellData.checkEmpty(); |
|
|
|
currentCellData.checkEmpty(); |
|
|
|
curRowContent.put(curCol, currentCellData); |
|
|
|
curRowContent.put(curCol, currentCellData); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
currentTagDeque.pop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void appendCurrentCellValue(String currentCellValue) { |
|
|
|
public void appendCurrentCellValue(char[] ch, int start, int length) { |
|
|
|
if (StringUtils.isEmpty(currentCellValue)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String currentTag = currentTagDeque.peek(); |
|
|
|
String currentTag = currentTagDeque.peek(); |
|
|
|
if (currentTag == null) { |
|
|
|
if (currentTag == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (CELL_FORMULA_TAG.equals(currentTag)) { |
|
|
|
if (CELL_FORMULA_TAG.equals(currentTag)) { |
|
|
|
currentCellData.setFormulaValue(currentCellValue); |
|
|
|
formulaStringBuilder.append(ch, start, length); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!CELL_VALUE_TAG.equals(currentTag) && !CELL_INLINE_STRING_VALUE_TAG.equals(currentTag)) { |
|
|
|
if (!CELL_VALUE_TAG.equals(currentTag) && !CELL_INLINE_STRING_VALUE_TAG.equals(currentTag)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
CellDataTypeEnum oldType = currentCellData.getType(); |
|
|
|
dataStringBuilder.append(ch, start, length); |
|
|
|
switch (oldType) { |
|
|
|
|
|
|
|
case DIRECT_STRING: |
|
|
|
|
|
|
|
case STRING: |
|
|
|
|
|
|
|
case ERROR: |
|
|
|
|
|
|
|
if (currentCellData.getStringValue() == null) { |
|
|
|
|
|
|
|
currentCellData.setStringValue(currentCellValue); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
currentCellData.setStringValue(currentCellData.getStringValue() + currentCellValue); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case BOOLEAN: |
|
|
|
|
|
|
|
if (currentCellData.getBooleanValue() == null) { |
|
|
|
|
|
|
|
currentCellData.setBooleanValue(BooleanUtils.valueOf(currentCellValue)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case NUMBER: |
|
|
|
|
|
|
|
case EMPTY: |
|
|
|
|
|
|
|
currentCellData.setType(CellDataTypeEnum.NUMBER); |
|
|
|
|
|
|
|
if (currentCellData.getNumberValue() == null) { |
|
|
|
|
|
|
|
currentCellData.setNumberValue(new BigDecimal(currentCellValue)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
throw new IllegalStateException("Cannot set values now"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|