Search in sources :

Example 6 with XlsxReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder in project easyexcel by alibaba.

the class CellTagHandler method startElement.

@Override
public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) {
    XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder();
    xlsxReadSheetHolder.setColumnIndex(PositionUtils.getCol(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_R), xlsxReadSheetHolder.getColumnIndex()));
    // t="s" ,it means String
    // t="str" ,it means String,but does not need to be read in the 'sharedStrings.xml'
    // t="inlineStr" ,it means String,but does not need to be read in the 'sharedStrings.xml'
    // t="b" ,it means Boolean
    // t="e" ,it means Error
    // t="n" ,it means Number
    // t is null ,it means Empty or Number
    CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_T));
    xlsxReadSheetHolder.setTempCellData(new ReadCellData<>(type));
    xlsxReadSheetHolder.setTempData(new StringBuilder());
    // Put in data transformation information
    String dateFormatIndex = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_S);
    int dateFormatIndexInteger;
    if (StringUtils.isEmpty(dateFormatIndex)) {
        dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;
    } else {
        dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
    }
    xlsxReadSheetHolder.getTempCellData().setDataFormatData(xlsxReadContext.xlsxReadWorkbookHolder().dataFormatData(dateFormatIndexInteger));
}
Also used : CellDataTypeEnum(com.alibaba.excel.enums.CellDataTypeEnum) XlsxReadSheetHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder)

Example 7 with XlsxReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder in project easyexcel by alibaba.

the class RowTagHandler method startElement.

@Override
public void startElement(XlsxReadContext xlsxReadContext, String name, Attributes attributes) {
    XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder();
    int rowIndex = PositionUtils.getRowByRowTagt(attributes.getValue(ExcelXmlConstants.ATTRIBUTE_R), xlsxReadSheetHolder.getRowIndex());
    Integer lastRowIndex = xlsxReadContext.readSheetHolder().getRowIndex();
    while (lastRowIndex + 1 < rowIndex) {
        xlsxReadContext.readRowHolder(new ReadRowHolder(lastRowIndex + 1, RowTypeEnum.EMPTY, xlsxReadSheetHolder.getGlobalConfiguration(), new LinkedHashMap<Integer, Cell>()));
        xlsxReadContext.analysisEventProcessor().endRow(xlsxReadContext);
        xlsxReadSheetHolder.setColumnIndex(null);
        xlsxReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>());
        lastRowIndex++;
    }
    xlsxReadSheetHolder.setRowIndex(rowIndex);
}
Also used : XlsxReadSheetHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder) ReadRowHolder(com.alibaba.excel.read.metadata.holder.ReadRowHolder) Cell(com.alibaba.excel.metadata.Cell) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XlsxReadSheetHolder (com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder)7 CellDataTypeEnum (com.alibaba.excel.enums.CellDataTypeEnum)2 Cell (com.alibaba.excel.metadata.Cell)2 ReadRowHolder (com.alibaba.excel.read.metadata.holder.ReadRowHolder)2 RowTypeEnum (com.alibaba.excel.enums.RowTypeEnum)1 ExcelAnalysisException (com.alibaba.excel.exception.ExcelAnalysisException)1 FormulaData (com.alibaba.excel.metadata.data.FormulaData)1 ReadCellData (com.alibaba.excel.metadata.data.ReadCellData)1 CsvReadSheetHolder (com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder)1 XlsReadSheetHolder (com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)1 LinkedHashMap (java.util.LinkedHashMap)1