Search in sources :

Example 11 with RowRecord

use of org.apache.poi.hssf.record.RowRecord in project poi by apache.

the class TestRowRecordsAggregate method testRowGet.

@Test
public void testRowGet() {
    RowRecordsAggregate rra = new RowRecordsAggregate();
    RowRecord rr = new RowRecord(4);
    rra.insertRow(rr);
    rra.insertRow(new RowRecord(1));
    RowRecord rr1 = rra.getRow(4);
    assertNotNull(rr1);
    assertEquals("Row number is 1", 4, rr1.getRowNumber());
    assertTrue("Row record retrieved is identical ", rr1 == rr);
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) Test(org.junit.Test)

Example 12 with RowRecord

use of org.apache.poi.hssf.record.RowRecord in project poi by apache.

the class TestRowBlocksReader method testAbnormalPivotTableRecords_bug46280.

@Test
public void testAbnormalPivotTableRecords_bug46280() {
    int SXVIEW_SID = ViewDefinitionRecord.sid;
    Record[] inRecs = { new RowRecord(0), new NumberRecord(), // normally MSODRAWING(0x00EC) would come here before SXVIEW
    new UnknownRecord(SXVIEW_SID, "dummydata (SXVIEW: View Definition)".getBytes(LocaleUtil.CHARSET_1252)), new WindowTwoRecord() };
    RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
    RowBlocksReader rbr = new RowBlocksReader(rs);
    if (rs.peekNextClass() == WindowTwoRecord.class) {
        // Should have stopped at the SXVIEW record
        fail("Identified bug 46280b");
    }
    RecordStream rbStream = rbr.getPlainRecordStream();
    assertEquals(inRecs[0], rbStream.getNext());
    assertEquals(inRecs[1], rbStream.getNext());
    assertFalse(rbStream.hasNext());
    assertTrue(rs.hasNext());
    assertEquals(inRecs[2], rs.getNext());
    assertEquals(inRecs[3], rs.getNext());
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ViewDefinitionRecord(org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Example 13 with RowRecord

use of org.apache.poi.hssf.record.RowRecord in project poi by apache.

the class TestSheet method testGutsRecord_bug45640.

/**
	 * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
	 * which in turn got the dimensions record out of alignment
	 */
@Test
public void testGutsRecord_bug45640() {
    InternalSheet sheet = InternalSheet.createSheet();
    sheet.addRow(new RowRecord(0));
    sheet.addRow(new RowRecord(1));
    sheet.groupRowRange(0, 1, true);
    sheet.toString();
    List<RecordBase> recs = sheet.getRecords();
    int count = 0;
    for (int i = 0; i < recs.size(); i++) {
        if (recs.get(i) instanceof GutsRecord) {
            count++;
        }
    }
    if (count == 2) {
        throw new AssertionFailedError("Identified bug 45640");
    }
    assertEquals(1, count);
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) GutsRecord(org.apache.poi.hssf.record.GutsRecord) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 14 with RowRecord

use of org.apache.poi.hssf.record.RowRecord in project poi by apache.

the class TestSheet method testMissingDims.

/**
	 * Some apps seem to write files with missing DIMENSION records.
	 * Excel(2007) tolerates this, so POI should too.
	 */
@Test
public void testMissingDims() {
    int rowIx = 5;
    int colIx = 6;
    NumberRecord nr = new NumberRecord();
    nr.setRow(rowIx);
    nr.setColumn((short) colIx);
    nr.setValue(3.0);
    List<Record> inRecs = new ArrayList<Record>();
    inRecs.add(BOFRecord.createSheetBOF());
    inRecs.add(new RowRecord(rowIx));
    inRecs.add(nr);
    inRecs.add(createWindow2Record());
    inRecs.add(EOFRecord.instance);
    InternalSheet sheet;
    try {
        sheet = createSheet(inRecs);
    } catch (RuntimeException e) {
        if ("DimensionsRecord was not found".equals(e.getMessage())) {
            throw new AssertionFailedError("Identified bug 46206");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, rowIx);
    Record[] outRecs = rv.getRecords();
    assertEquals(8, outRecs.length);
    DimensionsRecord dims = (DimensionsRecord) outRecs[5];
    assertEquals(rowIx, dims.getFirstRow());
    assertEquals(rowIx, dims.getLastRow());
    assertEquals(colIx, dims.getFirstCol());
    assertEquals(colIx, dims.getLastCol());
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) ArrayList(java.util.ArrayList) StringRecord(org.apache.poi.hssf.record.StringRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 15 with RowRecord

use of org.apache.poi.hssf.record.RowRecord in project poi by apache.

the class TestSheet method testRowAggregation.

/**
	 * Makes sure all rows registered for this sheet are aggregated, they were being skipped
	 *
	 */
@Test
public void testRowAggregation() {
    List<Record> records = new ArrayList<Record>();
    records.add(InternalSheet.createBOF());
    records.add(new DimensionsRecord());
    records.add(new RowRecord(0));
    records.add(new RowRecord(1));
    FormulaRecord formulaRecord = new FormulaRecord();
    formulaRecord.setCachedResultTypeString();
    records.add(formulaRecord);
    records.add(new StringRecord());
    records.add(new RowRecord(2));
    records.add(createWindow2Record());
    records.add(EOFRecord.instance);
    InternalSheet sheet = createSheet(records);
    assertNotNull("Row [2] was skipped", sheet.getRow(2));
}
Also used : FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) ArrayList(java.util.ArrayList) StringRecord(org.apache.poi.hssf.record.StringRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) Test(org.junit.Test)

Aggregations

RowRecord (org.apache.poi.hssf.record.RowRecord)17 Test (org.junit.Test)11 BlankRecord (org.apache.poi.hssf.record.BlankRecord)7 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)7 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)7 Record (org.apache.poi.hssf.record.Record)7 GutsRecord (org.apache.poi.hssf.record.GutsRecord)6 NumberRecord (org.apache.poi.hssf.record.NumberRecord)6 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)6 BOFRecord (org.apache.poi.hssf.record.BOFRecord)5 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)5 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)5 NoteRecord (org.apache.poi.hssf.record.NoteRecord)5 StringRecord (org.apache.poi.hssf.record.StringRecord)5 AssertionFailedError (junit.framework.AssertionFailedError)4 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 CellValueRecordInterface (org.apache.poi.hssf.record.CellValueRecordInterface)4 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)4 EOFRecord (org.apache.poi.hssf.record.EOFRecord)4 IndexRecord (org.apache.poi.hssf.record.IndexRecord)4