Search in sources :

Example 6 with MissingCellDummyRecord

use of org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord in project poi by apache.

the class TestMissingRecordAwareHSSFListener method testMissingCellRecords.

public void testMissingCellRecords() {
    openNormal();
    // Find the cell at 0,0
    int cell00 = -1;
    for (int i = 0; i < r.length; i++) {
        if (r[i] instanceof LabelSSTRecord) {
            LabelSSTRecord lr = (LabelSSTRecord) r[i];
            if (lr.getRow() == 0 && lr.getColumn() == 0) {
                cell00 = i;
            }
        }
    }
    assertTrue(cell00 > -1);
    // We have rows 0, 1, 2, 20 and 21
    // Row 0 has 1 entry, 0
    // Row 1 has 4 entries, 0+3
    // Row 2 has 6 entries, 0+5
    // Row 20 has 5 entries, 0-5
    // Row 21 has 7 entries, 0+1+3+5+6
    // Row 22 has 12 entries, 0+3+4+11
    // Row 0
    assertFalse(r[cell00 + 0] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 1] instanceof MissingCellDummyRecord);
    // Row 1
    assertFalse(r[cell00 + 2] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 3] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 4] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 5] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 6] instanceof MissingCellDummyRecord);
    // Row 2
    assertFalse(r[cell00 + 7] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 8] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 9] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 10] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 11] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 12] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 13] instanceof MissingCellDummyRecord);
    // Row 3-19
    assertFalse(r[cell00 + 14] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 15] instanceof MissingCellDummyRecord);
    // Row 20
    assertFalse(r[cell00 + 31] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 32] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 33] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 34] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 35] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 36] instanceof MissingCellDummyRecord);
    // Row 21
    assertFalse(r[cell00 + 37] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 38] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 39] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 40] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 41] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 42] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 43] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 44] instanceof MissingCellDummyRecord);
    // Row 22
    assertFalse(r[cell00 + 45] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 46] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 47] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 48] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 49] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 50] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 51] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 52] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 53] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 54] instanceof MissingCellDummyRecord);
    assertTrue(r[cell00 + 55] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 56] instanceof MissingCellDummyRecord);
    assertFalse(r[cell00 + 57] instanceof MissingCellDummyRecord);
    // Check some numbers
    MissingCellDummyRecord mc;
    mc = (MissingCellDummyRecord) r[cell00 + 3];
    assertEquals(1, mc.getRow());
    assertEquals(1, mc.getColumn());
    mc = (MissingCellDummyRecord) r[cell00 + 4];
    assertEquals(1, mc.getRow());
    assertEquals(2, mc.getColumn());
    mc = (MissingCellDummyRecord) r[cell00 + 8];
    assertEquals(2, mc.getRow());
    assertEquals(1, mc.getColumn());
    mc = (MissingCellDummyRecord) r[cell00 + 9];
    assertEquals(2, mc.getRow());
    assertEquals(2, mc.getColumn());
    mc = (MissingCellDummyRecord) r[cell00 + 55];
    assertEquals(22, mc.getRow());
    assertEquals(10, mc.getColumn());
}
Also used : LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)

Example 7 with MissingCellDummyRecord

use of org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord in project hutool by looly.

the class Excel03SaxReader method processRecord.

/**
 * HSSFListener 监听方法,处理 Record
 *
 * @param record 记录
 */
@Override
public void processRecord(Record record) {
    if (this.rid > -1 && this.curRid > this.rid) {
        // 指定Sheet之后的数据不再处理
        return;
    }
    if (record instanceof BoundSheetRecord) {
        // Sheet边界记录,此Record中可以获得Sheet名
        final BoundSheetRecord boundSheetRecord = (BoundSheetRecord) record;
        boundSheetRecords.add(boundSheetRecord);
        final String currentSheetName = boundSheetRecord.getSheetname();
        if (null != this.sheetName && StrUtil.equals(this.sheetName, currentSheetName)) {
            this.rid = this.boundSheetRecords.size() - 1;
        }
    } else if (record instanceof SSTRecord) {
        // 静态字符串表
        sstRecord = (SSTRecord) record;
    } else if (record instanceof BOFRecord) {
        BOFRecord bofRecord = (BOFRecord) record;
        if (bofRecord.getType() == BOFRecord.TYPE_WORKSHEET) {
            // 如果有需要,则建立子工作薄
            if (workbookBuildingListener != null && stubWorkbook == null) {
                stubWorkbook = workbookBuildingListener.getStubHSSFWorkbook();
            }
            curRid++;
        }
    } else if (record instanceof EOFRecord) {
        if (this.rid < 0 && null != this.sheetName) {
            throw new POIException("Sheet [{}] not exist!", this.sheetName);
        }
        processLastCellSheet();
    } else if (isProcessCurrentSheet()) {
        if (record instanceof MissingCellDummyRecord) {
            // 空值的操作
            MissingCellDummyRecord mc = (MissingCellDummyRecord) record;
            addToRowCellList(mc);
        } else if (record instanceof LastCellOfRowDummyRecord) {
            // 行结束
            processLastCell((LastCellOfRowDummyRecord) record);
        } else {
            // 处理单元格值
            processCellValue(record);
        }
    }
}
Also used : EOFRecord(org.apache.poi.hssf.record.EOFRecord) LastCellOfRowDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) MissingCellDummyRecord(org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) POIException(cn.hutool.poi.exceptions.POIException)

Aggregations

MissingCellDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord)7 LastCellOfRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord)6 BOFRecord (org.apache.poi.hssf.record.BOFRecord)5 LabelSSTRecord (org.apache.poi.hssf.record.LabelSSTRecord)5 StringRecord (org.apache.poi.hssf.record.StringRecord)4 BlankRecord (org.apache.poi.hssf.record.BlankRecord)3 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)3 NoteRecord (org.apache.poi.hssf.record.NoteRecord)3 NumberRecord (org.apache.poi.hssf.record.NumberRecord)3 MissingRowDummyRecord (org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord)2 BoolErrRecord (org.apache.poi.hssf.record.BoolErrRecord)2 LabelRecord (org.apache.poi.hssf.record.LabelRecord)2 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)2 RKRecord (org.apache.poi.hssf.record.RKRecord)2 RowRecord (org.apache.poi.hssf.record.RowRecord)2 POIException (cn.hutool.poi.exceptions.POIException)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1 CellValueRecordInterface (org.apache.poi.hssf.record.CellValueRecordInterface)1 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1