|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package com.alibaba.excel.analysis.v07.handlers; |
|
|
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle; |
|
|
|
|
import org.xml.sax.Attributes; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
|
|
import com.alibaba.excel.constant.BuiltinFormats; |
|
|
|
|
import com.alibaba.excel.constant.ExcelXmlConstants; |
|
|
|
@ -9,9 +8,13 @@ import com.alibaba.excel.context.xlsx.XlsxReadContext;
|
|
|
|
|
import com.alibaba.excel.enums.CellDataTypeEnum; |
|
|
|
|
import com.alibaba.excel.metadata.CellData; |
|
|
|
|
import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder; |
|
|
|
|
import com.alibaba.excel.util.BooleanUtils; |
|
|
|
|
import com.alibaba.excel.util.PositionUtils; |
|
|
|
|
import com.alibaba.excel.util.StringUtils; |
|
|
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle; |
|
|
|
|
import org.xml.sax.Attributes; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Cell Handler |
|
|
|
|
* |
|
|
|
@ -54,4 +57,54 @@ public class CellTagHandler extends AbstractXlsxTagHandler {
|
|
|
|
|
xssfCellStyle.getDataFormatString(), xlsxReadSheetHolder.getGlobalConfiguration().getLocale())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void endElement(XlsxReadContext xlsxReadContext, String name) { |
|
|
|
|
XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder(); |
|
|
|
|
CellData tempCellData = xlsxReadSheetHolder.getTempCellData(); |
|
|
|
|
StringBuilder tempData = xlsxReadSheetHolder.getTempData(); |
|
|
|
|
String tempDataString = tempData.toString(); |
|
|
|
|
CellDataTypeEnum oldType = tempCellData.getType(); |
|
|
|
|
switch (oldType) { |
|
|
|
|
case STRING: |
|
|
|
|
// In some cases, although cell type is a string, it may be an empty tag
|
|
|
|
|
if (StringUtils.isEmpty(tempDataString)) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
String stringValue = xlsxReadContext.readWorkbookHolder().getReadCache().get( |
|
|
|
|
Integer.valueOf(tempDataString)); |
|
|
|
|
tempCellData.setStringValue(stringValue); |
|
|
|
|
break; |
|
|
|
|
case DIRECT_STRING: |
|
|
|
|
case ERROR: |
|
|
|
|
tempCellData.setStringValue(tempDataString); |
|
|
|
|
tempCellData.setType(CellDataTypeEnum.STRING); |
|
|
|
|
break; |
|
|
|
|
case BOOLEAN: |
|
|
|
|
if (StringUtils.isEmpty(tempDataString)) { |
|
|
|
|
tempCellData.setType(CellDataTypeEnum.EMPTY); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
tempCellData.setBooleanValue(BooleanUtils.valueOf(tempData.toString())); |
|
|
|
|
break; |
|
|
|
|
case NUMBER: |
|
|
|
|
case EMPTY: |
|
|
|
|
if (StringUtils.isEmpty(tempDataString)) { |
|
|
|
|
tempCellData.setType(CellDataTypeEnum.EMPTY); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
tempCellData.setType(CellDataTypeEnum.NUMBER); |
|
|
|
|
tempCellData.setNumberValue(BigDecimal.valueOf(Double.parseDouble(tempDataString))); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new IllegalStateException("Cannot set values now"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (tempCellData.getStringValue() != null |
|
|
|
|
&& xlsxReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) { |
|
|
|
|
tempCellData.setStringValue(tempCellData.getStringValue()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tempCellData.checkEmpty(); |
|
|
|
|
xlsxReadSheetHolder.getCellMap().put(xlsxReadSheetHolder.getColumnIndex(), tempCellData); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|