Search in sources :

Example 31 with Record

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

the class TestValueRecordsAggregate method confirmMulBlank.

private void confirmMulBlank(int expectedTotalBlankCells, int expectedNumberOfMulBlankRecords, int expectedNumberOfSingleBlankRecords) {
    // assumed row ranges set-up by caller:
    final int firstRow = 1;
    final int lastRow = 2;
    final class BlankStats {

        public int countBlankCells;

        public int countMulBlankRecords;

        public int countSingleBlankRecords;
    }
    final BlankStats bs = new BlankStats();
    RecordVisitor rv = new RecordVisitor() {

        @Override
        public void visitRecord(Record r) {
            if (r instanceof MulBlankRecord) {
                MulBlankRecord mbr = (MulBlankRecord) r;
                bs.countMulBlankRecords++;
                bs.countBlankCells += mbr.getNumColumns();
            } else if (r instanceof BlankRecord) {
                bs.countSingleBlankRecords++;
                bs.countBlankCells++;
            }
        }
    };
    for (int rowIx = firstRow; rowIx <= lastRow; rowIx++) {
        if (valueRecord.rowHasCells(rowIx)) {
            valueRecord.visitCellsForRow(rowIx, rv);
        }
    }
    assertEquals(expectedTotalBlankCells, bs.countBlankCells);
    assertEquals(expectedNumberOfMulBlankRecords, bs.countMulBlankRecords);
    assertEquals(expectedNumberOfSingleBlankRecords, bs.countSingleBlankRecords);
}
Also used : MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) Record(org.apache.poi.hssf.record.Record) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) RecordVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor)

Example 32 with Record

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

the class TestRowRecordsAggregate method verifySharedValues.

private static int verifySharedValues(Record[] recs, Class<? extends SharedValueRecordBase> shfClass) {
    int result = 0;
    for (int i = 0; i < recs.length; i++) {
        Record rec = recs[i];
        if (rec.getClass() == shfClass) {
            result++;
            Record prevRec = recs[i - 1];
            if (!(prevRec instanceof FormulaRecord)) {
                fail("Bad record order at index " + i + ": Formula record expected but got (" + prevRec.getClass().getName() + ")");
            }
            verifySharedFormula((FormulaRecord) prevRec, rec);
        }
    }
    return result;
}
Also used : SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord)

Example 33 with Record

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

the class TestRowRecordsAggregate method testUnknownContinue_bug46280.

/**
	 * This problem was noted as the overt symptom of bug 46280.  The logic for skipping {@link
	 * UnknownRecord}s in the constructor {@link RowRecordsAggregate} did not allow for the
	 * possibility of tailing {@link ContinueRecord}s.<br/>
	 * The functionality change being tested here is actually not critical to the overall fix
	 * for bug 46280, since the fix involved making sure the that offending <i>PivotTable</i>
	 * records do not get into {@link RowRecordsAggregate}.<br/>
	 * This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
	 * UnknownRecord} has the potential of being 'continued'.
	 */
@Test
public void testUnknownContinue_bug46280() {
    Record[] inRecs = { new RowRecord(0), new NumberRecord(), new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)), new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)) };
    RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
    RowRecordsAggregate rra;
    try {
        rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
    } catch (RuntimeException e) {
        if (e.getMessage().startsWith("Unexpected record type")) {
            fail("Identified bug 46280a");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    rra.visitContainedRecords(rv);
    Record[] outRecs = rv.getRecords();
    assertEquals(5, outRecs.length);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Example 34 with Record

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

the class TestSharedValueManager method testPartiallyOverlappingRanges.

/**
	 * This bug happened when there were two or more shared formula ranges that overlapped.  POI
	 * would sometimes associate formulas in the overlapping region with the wrong shared formula
	 */
public void testPartiallyOverlappingRanges() {
    Record[] records;
    int attempt = 1;
    do {
        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook(SAMPLE_FILE_NAME);
        HSSFSheet sheet = wb.getSheetAt(0);
        RecordInspector.getRecords(sheet, 0);
        assertEquals("1+1", sheet.getRow(2).getCell(0).getCellFormula());
        if ("1+1".equals(sheet.getRow(3).getCell(0).getCellFormula())) {
            throw new AssertionFailedError("Identified bug - wrong shared formula record chosen" + " (attempt " + attempt + ")");
        }
        assertEquals("2+2", sheet.getRow(3).getCell(0).getCellFormula());
        records = RecordInspector.getRecords(sheet, 0);
    } while (attempt++ < MAX_ATTEMPTS);
    int count = 0;
    for (Record record : records) {
        if (record instanceof SharedFormulaRecord) {
            count++;
        }
    }
    assertEquals(2, count);
}
Also used : SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) Record(org.apache.poi.hssf.record.Record) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 35 with Record

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

the class TestBugs method bug51675.

@Test
public void bug51675() throws Exception {
    final List<Short> list = new ArrayList<Short>();
    HSSFWorkbook wb = openSample("51675.xls");
    HSSFSheet sh = wb.getSheetAt(0);
    InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
    PageSettingsBlock psb = (PageSettingsBlock) ish.getRecords().get(13);
    psb.visitContainedRecords(new RecordAggregate.RecordVisitor() {

        @Override
        public void visitRecord(Record r) {
            list.add(r.getSid());
        }
    });
    assertEquals(UnknownRecord.BITMAP_00E9, list.get(list.size() - 1).intValue());
    assertEquals(UnknownRecord.HEADER_FOOTER_089C, list.get(list.size() - 2).intValue());
    wb.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) ArrayList(java.util.ArrayList) PageSettingsBlock(org.apache.poi.hssf.record.aggregates.PageSettingsBlock) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) Record(org.apache.poi.hssf.record.Record) EmbeddedObjectRefSubRecord(org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) FormulaRecordAggregate(org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate) RecordAggregate(org.apache.poi.hssf.record.aggregates.RecordAggregate) Test(org.junit.Test)

Aggregations

Record (org.apache.poi.hssf.record.Record)78 EOFRecord (org.apache.poi.hssf.record.EOFRecord)42 BOFRecord (org.apache.poi.hssf.record.BOFRecord)36 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)36 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)30 Test (org.junit.Test)25 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)24 NumberRecord (org.apache.poi.hssf.record.NumberRecord)24 RowRecord (org.apache.poi.hssf.record.RowRecord)24 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)23 NameRecord (org.apache.poi.hssf.record.NameRecord)23 ArrayList (java.util.ArrayList)21 EscherRecord (org.apache.poi.ddf.EscherRecord)21 BlankRecord (org.apache.poi.hssf.record.BlankRecord)21 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)21 UnknownRecord (org.apache.poi.hssf.record.UnknownRecord)19 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)18 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)18 StringRecord (org.apache.poi.hssf.record.StringRecord)18 NoteRecord (org.apache.poi.hssf.record.NoteRecord)17