Search in sources :

Example 1 with UncalcedRecord

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

the class InternalSheet method visitContainedRecords.

public void visitContainedRecords(RecordVisitor rv, int offset) {
    PositionTrackingVisitor ptv = new PositionTrackingVisitor(rv, offset);
    boolean haveSerializedIndex = false;
    for (int k = 0; k < _records.size(); k++) {
        RecordBase record = _records.get(k);
        if (record instanceof RecordAggregate) {
            RecordAggregate agg = (RecordAggregate) record;
            agg.visitContainedRecords(ptv);
        } else {
            ptv.visitRecord((Record) record);
        }
        // If the BOF record was just serialized then add the IndexRecord
        if (record instanceof BOFRecord) {
            if (!haveSerializedIndex) {
                haveSerializedIndex = true;
                //  and one shouldn't go in after that!
                if (_isUncalced) {
                    ptv.visitRecord(new UncalcedRecord());
                }
                //remove this guard. So be safe it is left here.
                if (_rowsAggregate != null) {
                    // find forward distance to first RowRecord
                    int initRecsSize = getSizeOfInitialSheetRecords(k);
                    int currentPos = ptv.getPosition();
                    ptv.visitRecord(_rowsAggregate.createIndexRecord(currentPos, initRecsSize));
                }
            }
        }
    }
}
Also used : PositionTrackingVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) CustomViewSettingsRecordAggregate(org.apache.poi.hssf.record.aggregates.CustomViewSettingsRecordAggregate) RecordAggregate(org.apache.poi.hssf.record.aggregates.RecordAggregate) ChartSubstreamRecordAggregate(org.apache.poi.hssf.record.aggregates.ChartSubstreamRecordAggregate) BOFRecord(org.apache.poi.hssf.record.BOFRecord)

Example 2 with UncalcedRecord

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

the class TestSheet method testUncalcSize_bug45066.

/**
	 * Prior to bug 45066, POI would get the estimated sheet size wrong
	 * when an <tt>UncalcedRecord</tt> was present.<p/>
	 */
@Test
public void testUncalcSize_bug45066() {
    List<Record> records = new ArrayList<Record>();
    records.add(BOFRecord.createSheetBOF());
    records.add(new UncalcedRecord());
    records.add(new DimensionsRecord());
    records.add(createWindow2Record());
    records.add(EOFRecord.instance);
    InternalSheet sheet = createSheet(records);
    // The original bug was due to different logic for collecting records for sizing and
    // serialization. The code has since been refactored into a single method for visiting
    // all contained records.  Now this test is much less interesting
    SizeCheckingRecordVisitor scrv = new SizeCheckingRecordVisitor();
    sheet.visitContainedRecords(scrv, 0);
    assertEquals(90, scrv.getTotalSize());
}
Also used : UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) 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) Test(org.junit.Test)

Aggregations

BOFRecord (org.apache.poi.hssf.record.BOFRecord)2 UncalcedRecord (org.apache.poi.hssf.record.UncalcedRecord)2 ArrayList (java.util.ArrayList)1 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)1 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)1 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)1 EOFRecord (org.apache.poi.hssf.record.EOFRecord)1 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)1 GutsRecord (org.apache.poi.hssf.record.GutsRecord)1 IndexRecord (org.apache.poi.hssf.record.IndexRecord)1 MergeCellsRecord (org.apache.poi.hssf.record.MergeCellsRecord)1 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)1 NoteRecord (org.apache.poi.hssf.record.NoteRecord)1 NumberRecord (org.apache.poi.hssf.record.NumberRecord)1 ObjRecord (org.apache.poi.hssf.record.ObjRecord)1 Record (org.apache.poi.hssf.record.Record)1 RecordBase (org.apache.poi.hssf.record.RecordBase)1 RowRecord (org.apache.poi.hssf.record.RowRecord)1