Search in sources :

Example 1 with XlsReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder in project easyexcel by alibaba.

the class TextObjectRecordHandler method processRecord.

@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    TextObjectRecord tor = (TextObjectRecord) record;
    XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
    Integer tempObjectIndex = xlsReadSheetHolder.getTempObjectIndex();
    if (tempObjectIndex == null) {
        LOGGER.debug("tempObjectIndex is null.");
        return;
    }
    xlsReadSheetHolder.getObjectCacheMap().put(tempObjectIndex, tor.getStr().getString());
    xlsReadSheetHolder.setTempObjectIndex(null);
}
Also used : TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)

Example 2 with XlsReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder in project easyexcel by alibaba.

the class StringRecordHandler method processRecord.

@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    // String for formula
    StringRecord srec = (StringRecord) record;
    XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
    CellData<?> tempCellData = xlsReadSheetHolder.getTempCellData();
    if (tempCellData == null) {
        LOGGER.warn("String type formula but no value found.");
        return;
    }
    tempCellData.setStringValue(srec.getString());
    xlsReadSheetHolder.getCellMap().put(tempCellData.getColumnIndex(), tempCellData);
    xlsReadSheetHolder.setTempCellData(null);
}
Also used : StringRecord(org.apache.poi.hssf.record.StringRecord) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)

Example 3 with XlsReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder in project easyexcel by alibaba.

the class EofRecordHandler method processRecord.

@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    if (xlsReadContext.readSheetHolder() == null) {
        return;
    }
    // Sometimes tables lack the end record of the last column
    if (!xlsReadContext.xlsReadSheetHolder().getCellMap().isEmpty()) {
        XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
        // Forge a termination data
        xlsReadContext.readRowHolder(new ReadRowHolder(xlsReadContext.xlsReadSheetHolder().getRowIndex() + 1, xlsReadSheetHolder.getTempRowType(), xlsReadContext.readSheetHolder().getGlobalConfiguration(), xlsReadSheetHolder.getCellMap()));
        xlsReadContext.analysisEventProcessor().endRow(xlsReadContext);
        xlsReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>());
        xlsReadSheetHolder.setTempRowType(RowTypeEnum.EMPTY);
    }
    xlsReadContext.analysisEventProcessor().endSheet(xlsReadContext);
}
Also used : ReadRowHolder(com.alibaba.excel.read.metadata.holder.ReadRowHolder) Cell(com.alibaba.excel.metadata.Cell) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)

Example 4 with XlsReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder in project easyexcel by alibaba.

the class DummyRecordHandler method processRecord.

@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
    XlsReadSheetHolder xlsReadSheetHolder = xlsReadContext.xlsReadSheetHolder();
    if (record instanceof LastCellOfRowDummyRecord) {
        // End of this row
        LastCellOfRowDummyRecord lcrdr = (LastCellOfRowDummyRecord) record;
        xlsReadSheetHolder.setRowIndex(lcrdr.getRow());
        xlsReadContext.readRowHolder(new ReadRowHolder(lcrdr.getRow(), xlsReadSheetHolder.getTempRowType(), xlsReadContext.readSheetHolder().getGlobalConfiguration(), xlsReadSheetHolder.getCellMap()));
        xlsReadContext.analysisEventProcessor().endRow(xlsReadContext);
        xlsReadSheetHolder.setCellMap(new LinkedHashMap<Integer, Cell>());
        xlsReadSheetHolder.setTempRowType(RowTypeEnum.EMPTY);
    } else if (record instanceof MissingCellDummyRecord) {
        MissingCellDummyRecord mcdr = (MissingCellDummyRecord) record;
        // https://github.com/alibaba/easyexcel/issues/2236
        // Some abnormal XLS, in the case of data already exist, or there will be a "MissingCellDummyRecord"
        // records, so if the existing data, empty data is ignored
        xlsReadSheetHolder.getCellMap().putIfAbsent(mcdr.getColumn(), ReadCellData.newEmptyInstance(mcdr.getRow(), mcdr.getColumn()));
    }
}
Also used : LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) ReadRowHolder(com.alibaba.excel.read.metadata.holder.ReadRowHolder) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord) Cell(com.alibaba.excel.metadata.Cell) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)

Example 5 with XlsReadSheetHolder

use of com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder in project easyexcel by alibaba.

the class AnalysisContextImpl method currentSheet.

@Override
public void currentSheet(ReadSheet readSheet) {
    switch(readWorkbookHolder.getExcelType()) {
        case XLS:
            readSheetHolder = new XlsReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        case XLSX:
            readSheetHolder = new XlsxReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        case CSV:
            readSheetHolder = new CsvReadSheetHolder(readSheet, readWorkbookHolder);
            break;
        default:
            break;
    }
    currentReadHolder = readSheetHolder;
    if (readWorkbookHolder.getHasReadSheet().contains(readSheetHolder.getSheetNo())) {
        throw new ExcelAnalysisException("Cannot read sheet repeatedly.");
    }
    readWorkbookHolder.getHasReadSheet().add(readSheetHolder.getSheetNo());
    if (log.isDebugEnabled()) {
        log.debug("Began to read:{}", readSheetHolder);
    }
}
Also used : XlsxReadSheetHolder(com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder) CsvReadSheetHolder(com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder) XlsReadSheetHolder(com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Aggregations

XlsReadSheetHolder (com.alibaba.excel.read.metadata.holder.xls.XlsReadSheetHolder)5 Cell (com.alibaba.excel.metadata.Cell)2 ReadRowHolder (com.alibaba.excel.read.metadata.holder.ReadRowHolder)2 ExcelAnalysisException (com.alibaba.excel.exception.ExcelAnalysisException)1 CsvReadSheetHolder (com.alibaba.excel.read.metadata.holder.csv.CsvReadSheetHolder)1 XlsxReadSheetHolder (com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder)1 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)1 MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)1 StringRecord (org.apache.poi.hssf.record.StringRecord)1 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)1