Search in sources :

Example 1 with DimensionsRecord

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

the class TestSheet method testCloneMulBlank_bug46776.

@Test
public void testCloneMulBlank_bug46776() {
    Record[] recs = { InternalSheet.createBOF(), new DimensionsRecord(), new RowRecord(1), new MulBlankRecord(1, 3, new short[] { 0x0F, 0x0F, 0x0F }), new RowRecord(2), createWindow2Record(), EOFRecord.instance };
    InternalSheet sheet = createSheet(Arrays.asList(recs));
    InternalSheet sheet2;
    try {
        sheet2 = sheet.cloneSheet();
    } catch (RuntimeException e) {
        if (e.getMessage().equals("The class org.apache.poi.hssf.record.MulBlankRecord needs to define a clone method")) {
            throw new AssertionFailedError("Identified bug 46776");
        }
        throw e;
    }
    RecordCollector rc = new RecordCollector();
    sheet2.visitContainedRecords(rc, 0);
    Record[] clonedRecs = rc.getRecords();
    // +2 for INDEX and DBCELL
    assertEquals(recs.length + 2, clonedRecs.length);
}
Also used : MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) 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) AssertionFailedError(junit.framework.AssertionFailedError) Test(org.junit.Test)

Example 2 with DimensionsRecord

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

the class TestSheet method testSheetDimensions.

@Test
public void testSheetDimensions() throws IOException {
    InternalSheet sheet = InternalSheet.createSheet();
    DimensionsRecord dimensions = (DimensionsRecord) sheet.findFirstRecordBySid(DimensionsRecord.sid);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    // plus pne
    assertEquals(1, dimensions.getLastCol());
    // plus pne
    assertEquals(1, dimensions.getLastRow());
    RowRecord rr = new RowRecord(0);
    sheet.addRow(rr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    assertEquals(1, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
    CellValueRecordInterface cvr;
    cvr = new BlankRecord();
    cvr.setColumn((short) 0);
    cvr.setRow(0);
    sheet.addValueRecord(0, cvr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    assertEquals(1, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
    cvr = new BlankRecord();
    cvr.setColumn((short) 1);
    cvr.setRow(0);
    sheet.addValueRecord(0, cvr);
    assertEquals(0, dimensions.getFirstCol());
    assertEquals(0, dimensions.getFirstRow());
    //YK:  failed until Bugzilla 53414 was fixed
    assertEquals(2, dimensions.getLastCol());
    assertEquals(1, dimensions.getLastRow());
}
Also used : MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) RowRecord(org.apache.poi.hssf.record.RowRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) Test(org.junit.Test)

Example 3 with DimensionsRecord

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

the class TestSheet method testCreateSheet.

@Test
public void testCreateSheet() {
    // Check we're adding row and cell aggregates
    List<Record> records = new ArrayList<Record>();
    records.add(BOFRecord.createSheetBOF());
    records.add(new DimensionsRecord());
    records.add(createWindow2Record());
    records.add(EOFRecord.instance);
    InternalSheet sheet = createSheet(records);
    Record[] outRecs = getSheetRecords(sheet, 0);
    int pos = 0;
    assertTrue(outRecs[pos++] instanceof BOFRecord);
    assertTrue(outRecs[pos++] instanceof IndexRecord);
    assertTrue(outRecs[pos++] instanceof DimensionsRecord);
    assertTrue(outRecs[pos++] instanceof WindowTwoRecord);
    assertTrue(outRecs[pos++] instanceof EOFRecord);
}
Also used : EOFRecord(org.apache.poi.hssf.record.EOFRecord) 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) BOFRecord(org.apache.poi.hssf.record.BOFRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) Test(org.junit.Test)

Example 4 with DimensionsRecord

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

the class TestHSSFSheet method protectSheetRecordOrder_bug47363a.

/**
     * {@link PasswordRecord} belongs with the rest of the Worksheet Protection Block
     * (which should be before {@link DimensionsRecord}).
     */
@Test
public void protectSheetRecordOrder_bug47363a() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet s = wb.createSheet();
    s.protectSheet("secret");
    RecordCollector rc = new RecordCollector();
    s.getSheet().visitContainedRecords(rc, 0);
    Record[] recs = rc.getRecords();
    int nRecs = recs.length;
    if (recs[nRecs - 2] instanceof PasswordRecord && recs[nRecs - 5] instanceof DimensionsRecord) {
        fail("Identified bug 47363a - PASSWORD after DIMENSION");
    }
    // Check that protection block is together, and before DIMENSION
    confirmRecordClass(recs, nRecs - 4, DimensionsRecord.class);
    confirmRecordClass(recs, nRecs - 9, ProtectRecord.class);
    confirmRecordClass(recs, nRecs - 8, ObjectProtectRecord.class);
    confirmRecordClass(recs, nRecs - 7, ScenarioProtectRecord.class);
    confirmRecordClass(recs, nRecs - 6, PasswordRecord.class);
    wb.close();
}
Also used : PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) VCenterRecord(org.apache.poi.hssf.record.VCenterRecord) ScenarioProtectRecord(org.apache.poi.hssf.record.ScenarioProtectRecord) GridsetRecord(org.apache.poi.hssf.record.GridsetRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) FtCblsSubRecord(org.apache.poi.hssf.record.FtCblsSubRecord) ObjectProtectRecord(org.apache.poi.hssf.record.ObjectProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) LbsDataSubRecord(org.apache.poi.hssf.record.LbsDataSubRecord) Record(org.apache.poi.hssf.record.Record) ObjRecord(org.apache.poi.hssf.record.ObjRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) SubRecord(org.apache.poi.hssf.record.SubRecord) HCenterRecord(org.apache.poi.hssf.record.HCenterRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) Test(org.junit.Test)

Example 5 with DimensionsRecord

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

the class InternalSheet method addRow.

/**
     * Adds a row record to the sheet
     *
     * <P>
     * This method is "loc" sensitive.  Meaning you need to set LOC to where you
     * want it to start searching.  If you don't know do this: setLoc(getDimsLoc).
     * When adding several rows you can just start at the last one by leaving loc
     * at what this sets it to.
     *
     * @param row the row record to be added
     */
public void addRow(RowRecord row) {
    if (log.check(POILogger.DEBUG))
        log.log(POILogger.DEBUG, "addRow ");
    DimensionsRecord d = _dimensions;
    if (row.getRowNumber() >= d.getLastRow()) {
        d.setLastRow(row.getRowNumber() + 1);
    }
    if (row.getRowNumber() < d.getFirstRow()) {
        d.setFirstRow(row.getRowNumber());
    }
    //If the row exists remove it, so that any cells attached to the row are removed
    RowRecord existingRow = _rowsAggregate.getRow(row.getRowNumber());
    if (existingRow != null) {
        _rowsAggregate.removeRow(existingRow);
    }
    _rowsAggregate.insertRow(row);
    if (log.check(POILogger.DEBUG))
        log.log(POILogger.DEBUG, "exit addRow");
}
Also used : RowRecord(org.apache.poi.hssf.record.RowRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord)

Aggregations

DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)12 RowRecord (org.apache.poi.hssf.record.RowRecord)8 Test (org.junit.Test)8 BlankRecord (org.apache.poi.hssf.record.BlankRecord)7 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)7 ObjRecord (org.apache.poi.hssf.record.ObjRecord)7 Record (org.apache.poi.hssf.record.Record)7 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)7 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)6 BOFRecord (org.apache.poi.hssf.record.BOFRecord)6 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)6 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)6 EOFRecord (org.apache.poi.hssf.record.EOFRecord)6 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)6 GutsRecord (org.apache.poi.hssf.record.GutsRecord)6 IndexRecord (org.apache.poi.hssf.record.IndexRecord)6 MergeCellsRecord (org.apache.poi.hssf.record.MergeCellsRecord)6 NoteRecord (org.apache.poi.hssf.record.NoteRecord)6 NumberRecord (org.apache.poi.hssf.record.NumberRecord)6 StringRecord (org.apache.poi.hssf.record.StringRecord)6