Search in sources :

Example 1 with RecordBase

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

the class RecordOrderer method findDataValidationTableInsertPos.

/**
	 * Finds the index where the sheet validations header record should be inserted
	 * @param records the records for this sheet
	 *
	 * + WINDOW2
	 * o SCL
	 * o PANE
	 * oo SELECTION
	 * o STANDARDWIDTH
	 * oo MERGEDCELLS
	 * o LABELRANGES
	 * o PHONETICPR
	 * o Conditional Formatting Table
	 * o Hyperlink Table
	 * o Data Validity Table
	 * o SHEETLAYOUT
	 * o SHEETPROTECTION
	 * o RANGEPROTECTION
	 * + EOF
	 */
private static int findDataValidationTableInsertPos(List<RecordBase> records) {
    int i = records.size() - 1;
    if (!(records.get(i) instanceof EOFRecord)) {
        throw new IllegalStateException("Last sheet record should be EOFRecord");
    }
    while (i > 0) {
        i--;
        RecordBase rb = records.get(i);
        if (isDVTPriorRecord(rb)) {
            Record nextRec = (Record) records.get(i + 1);
            if (!isDVTSubsequentRecord(nextRec.getSid())) {
                throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName() + ") found after (" + rb.getClass().getName() + ")");
            }
            return i + 1;
        }
        Record rec = (Record) rb;
        if (!isDVTSubsequentRecord(rec.getSid())) {
            throw new IllegalStateException("Unexpected (" + rec.getClass().getName() + ") while looking for DV Table insert pos");
        }
    }
    return 0;
}
Also used : EOFRecord(org.apache.poi.hssf.record.EOFRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) DrawingSelectionRecord(org.apache.poi.hssf.record.DrawingSelectionRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) DefaultColWidthRecord(org.apache.poi.hssf.record.DefaultColWidthRecord) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) DefaultRowHeightRecord(org.apache.poi.hssf.record.DefaultRowHeightRecord) GridsetRecord(org.apache.poi.hssf.record.GridsetRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) BoolErrRecord(org.apache.poi.hssf.record.BoolErrRecord) Record(org.apache.poi.hssf.record.Record) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) PrintHeadersRecord(org.apache.poi.hssf.record.PrintHeadersRecord) RefModeRecord(org.apache.poi.hssf.record.RefModeRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) CalcCountRecord(org.apache.poi.hssf.record.CalcCountRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) PrintGridlinesRecord(org.apache.poi.hssf.record.PrintGridlinesRecord) IterationRecord(org.apache.poi.hssf.record.IterationRecord) CalcModeRecord(org.apache.poi.hssf.record.CalcModeRecord) SelectionRecord(org.apache.poi.hssf.record.SelectionRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) RKRecord(org.apache.poi.hssf.record.RKRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) DVALRecord(org.apache.poi.hssf.record.DVALRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) DeltaRecord(org.apache.poi.hssf.record.DeltaRecord) PaneRecord(org.apache.poi.hssf.record.PaneRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) FeatRecord(org.apache.poi.hssf.record.FeatRecord) ViewDefinitionRecord(org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord) SaveRecalcRecord(org.apache.poi.hssf.record.SaveRecalcRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) 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)

Example 2 with RecordBase

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

the class ValueRecordsAggregate method visitCellsForRow.

public void visitCellsForRow(int rowIndex, RecordVisitor rv) {
    CellValueRecordInterface[] rowCells = records[rowIndex];
    if (rowCells == null) {
        throw new IllegalArgumentException("Row [" + rowIndex + "] is empty");
    }
    for (int i = 0; i < rowCells.length; i++) {
        RecordBase cvr = (RecordBase) rowCells[i];
        if (cvr == null) {
            continue;
        }
        int nBlank = countBlanks(rowCells, i);
        if (nBlank > 1) {
            rv.visitRecord(createMBR(rowCells, i, nBlank));
            i += nBlank - 1;
        } else if (cvr instanceof RecordAggregate) {
            RecordAggregate agg = (RecordAggregate) cvr;
            agg.visitContainedRecords(rv);
        } else {
            rv.visitRecord((Record) cvr);
        }
    }
}
Also used : CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) RecordBase(org.apache.poi.hssf.record.RecordBase) Record(org.apache.poi.hssf.record.Record) StringRecord(org.apache.poi.hssf.record.StringRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord)

Example 3 with RecordBase

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

the class ValueRecordsAggregate method getRowSerializedSize.

private static int getRowSerializedSize(CellValueRecordInterface[] rowCells) {
    if (rowCells == null) {
        return 0;
    }
    int result = 0;
    for (int i = 0; i < rowCells.length; i++) {
        RecordBase cvr = (RecordBase) rowCells[i];
        if (cvr == null) {
            continue;
        }
        int nBlank = countBlanks(rowCells, i);
        if (nBlank > 1) {
            result += (10 + 2 * nBlank);
            i += nBlank - 1;
        } else {
            result += cvr.getRecordSize();
        }
    }
    return result;
}
Also used : RecordBase(org.apache.poi.hssf.record.RecordBase)

Example 4 with RecordBase

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

the class TestSheet method confirmAggregatedRecords.

private void confirmAggregatedRecords(List<Record> recordStream) {
    InternalSheet sheet = InternalSheet.createSheet();
    sheet.getRecords().clear();
    sheet.getRecords().addAll(recordStream);
    List<RecordBase> sheetRecords = sheet.getRecords();
    DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
    sheet.aggregateDrawingRecords(drawingManager, false);
    assertEquals(4, sheetRecords.size());
    assertEquals(BOFRecord.sid, ((Record) sheetRecords.get(0)).getSid());
    assertEquals(EscherAggregate.sid, ((Record) sheetRecords.get(1)).getSid());
    assertEquals(WindowTwoRecord.sid, ((Record) sheetRecords.get(2)).getSid());
    assertEquals(EOFRecord.sid, ((Record) sheetRecords.get(3)).getSid());
}
Also used : RecordBase(org.apache.poi.hssf.record.RecordBase) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord)

Example 5 with RecordBase

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

the class TestHSSFWorkbook method sheetSerializeSizeMismatch_bug45066.

/**
     * If Sheet.getSize() returns a different result to Sheet.serialize(), this will cause the BOF
     * records to be written with invalid offset indexes.  Excel does not like this, and such
     * errors are particularly hard to track down.  This test ensures that HSSFWorkbook throws
     * a specific exception as soon as the situation is detected. See bugzilla 45066
     * @throws IOException 
     */
@Test
public void sheetSerializeSizeMismatch_bug45066() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    InternalSheet sheet = wb.createSheet("Sheet1").getSheet();
    List<RecordBase> sheetRecords = sheet.getRecords();
    // one way (of many) to cause the discrepancy is with a badly behaved record:
    sheetRecords.add(new BadlyBehavedRecord());
    // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
    try {
        wb.getBytes();
        fail("Identified bug 45066 a");
    } catch (IllegalStateException e) {
        // Expected badly behaved sheet record to cause exception
        assertTrue(e.getMessage().startsWith("Actual serialized sheet size"));
    }
    wb.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) RecordBase(org.apache.poi.hssf.record.RecordBase) Test(org.junit.Test)

Aggregations

RecordBase (org.apache.poi.hssf.record.RecordBase)29 Test (org.junit.Test)14 EOFRecord (org.apache.poi.hssf.record.EOFRecord)12 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)12 Record (org.apache.poi.hssf.record.Record)12 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)9 NoteRecord (org.apache.poi.hssf.record.NoteRecord)9 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)9 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)8 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)8 ObjRecord (org.apache.poi.hssf.record.ObjRecord)8 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)8 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 EscherRecord (org.apache.poi.ddf.EscherRecord)7 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)7 BOFRecord (org.apache.poi.hssf.record.BOFRecord)6 ArrayList (java.util.ArrayList)5 RowRecordsAggregate (org.apache.poi.hssf.record.aggregates.RowRecordsAggregate)5 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)4