Search in sources :

Example 6 with EOFRecord

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

the class TestEventRecordFactory method testProcessRecords.

/**
     * tests that the records can be processed and properly return 
     * values.
     */
public void testProcessRecords() {
    // hack to pass boolean by ref into inner class
    final boolean[] wascalled = { false };
    ERFListener listener = new ERFListener() {

        @Override
        public boolean processRecord(Record rec) {
            wascalled[0] = true;
            assertTrue("must be BOFRecord got SID=" + rec.getSid(), (rec.getSid() == BOFRecord.sid));
            return true;
        }
    };
    EventRecordFactory factory = new EventRecordFactory(listener, new short[] { BOFRecord.sid });
    BOFRecord bof = new BOFRecord();
    bof.setBuild((short) 0);
    bof.setBuildYear((short) 1999);
    bof.setRequiredVersion(123);
    bof.setType(BOFRecord.TYPE_WORKBOOK);
    bof.setVersion((short) 0x06);
    bof.setHistoryBitMask(BOFRecord.HISTORY_MASK);
    EOFRecord eof = EOFRecord.instance;
    byte[] bytes = new byte[bof.getRecordSize() + eof.getRecordSize()];
    int offset = 0;
    offset = bof.serialize(offset, bytes);
    offset = eof.serialize(offset, bytes);
    factory.processRecords(new ByteArrayInputStream(bytes));
    assertTrue("The record listener must be called", wascalled[0]);
}
Also used : EOFRecord(org.apache.poi.hssf.record.EOFRecord) ByteArrayInputStream(java.io.ByteArrayInputStream) Record(org.apache.poi.hssf.record.Record) BOFRecord(org.apache.poi.hssf.record.BOFRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord)

Example 7 with EOFRecord

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

the class TestReadWriteChart method testBOFandEOFRecords.

/**
     * In the presence of a chart we need to make sure BOF/EOF records still exist.
     */
@Test
public void testBOFandEOFRecords() throws Exception {
    HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("SimpleChart.xls");
    HSSFSheet sheet = workbook.getSheetAt(0);
    HSSFRow firstRow = sheet.getRow(0);
    HSSFCell firstCell = firstRow.getCell(0);
    //System.out.println("first assertion for date");
    Calendar calExp = LocaleUtil.getLocaleCalendar(2000, 0, 1, 10, 51, 2);
    Date dateAct = HSSFDateUtil.getJavaDate(firstCell.getNumericCellValue(), false);
    assertEquals(calExp.getTime(), dateAct);
    HSSFRow row = sheet.createRow(15);
    HSSFCell cell = row.createCell(1);
    cell.setCellValue(22);
    InternalSheet newSheet = workbook.getSheetAt(0).getSheet();
    List<RecordBase> records = newSheet.getRecords();
    assertTrue(records.get(0) instanceof BOFRecord);
    assertTrue(records.get(records.size() - 1) instanceof EOFRecord);
    workbook.close();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) EOFRecord(org.apache.poi.hssf.record.EOFRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) Calendar(java.util.Calendar) BOFRecord(org.apache.poi.hssf.record.BOFRecord) Date(java.util.Date) Test(org.junit.Test)

Example 8 with EOFRecord

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

the class TestLinkTable method testAddNameX.

public void testAddNameX() {
    WorkbookRecordList wrl = new WorkbookRecordList();
    wrl.add(0, new BOFRecord());
    wrl.add(1, new CountryRecord());
    wrl.add(2, EOFRecord.instance);
    int numberOfSheets = 3;
    LinkTable tbl = new LinkTable(numberOfSheets, wrl);
    // creation of a new LinkTable insert two new records: SupBookRecord followed by ExternSheetRecord
    // assure they are in place:
    //    [BOFRecord]
    //    [CountryRecord]
    //    [SUPBOOK Internal References  nSheets= 3]
    //    [EXTERNSHEET]
    //    [EOFRecord]
    assertEquals(5, wrl.getRecords().size());
    assertTrue(wrl.get(2) instanceof SupBookRecord);
    SupBookRecord sup1 = (SupBookRecord) wrl.get(2);
    assertEquals(numberOfSheets, sup1.getNumberOfSheets());
    assertTrue(wrl.get(3) instanceof ExternSheetRecord);
    ExternSheetRecord extSheet = (ExternSheetRecord) wrl.get(3);
    assertEquals(0, extSheet.getNumOfRefs());
    assertNull(tbl.getNameXPtg("ISODD", -1));
    //still have five records
    assertEquals(5, wrl.getRecords().size());
    // adds two new rercords
    NameXPtg namex1 = tbl.addNameXPtg("ISODD");
    assertEquals(0, namex1.getSheetRefIndex());
    assertEquals(0, namex1.getNameIndex());
    assertEquals(namex1.toString(), tbl.getNameXPtg("ISODD", -1).toString());
    // Can only find on the right sheet ref, if restricting
    assertEquals(namex1.toString(), tbl.getNameXPtg("ISODD", 0).toString());
    assertNull(tbl.getNameXPtg("ISODD", 1));
    assertNull(tbl.getNameXPtg("ISODD", 2));
    // assure they are in place:
    //    [BOFRecord]
    //    [CountryRecord]
    //    [SUPBOOK Internal References  nSheets= 3]
    //    [SUPBOOK Add-In Functions nSheets= 1]
    //    [EXTERNALNAME .name    = ISODD]
    //    [EXTERNSHEET]
    //    [EOFRecord]
    assertEquals(7, wrl.getRecords().size());
    assertTrue(wrl.get(3) instanceof SupBookRecord);
    SupBookRecord sup2 = (SupBookRecord) wrl.get(3);
    assertTrue(sup2.isAddInFunctions());
    assertTrue(wrl.get(4) instanceof ExternalNameRecord);
    ExternalNameRecord ext1 = (ExternalNameRecord) wrl.get(4);
    assertEquals("ISODD", ext1.getText());
    assertTrue(wrl.get(5) instanceof ExternSheetRecord);
    assertEquals(1, extSheet.getNumOfRefs());
    //check that
    assertEquals(0, tbl.resolveNameXIx(namex1.getSheetRefIndex(), namex1.getNameIndex()));
    assertEquals("ISODD", tbl.resolveNameXText(namex1.getSheetRefIndex(), namex1.getNameIndex(), null));
    assertNull(tbl.getNameXPtg("ISEVEN", -1));
    // adds two new rercords
    NameXPtg namex2 = tbl.addNameXPtg("ISEVEN");
    assertEquals(0, namex2.getSheetRefIndex());
    // name index increased by one
    assertEquals(1, namex2.getNameIndex());
    assertEquals(namex2.toString(), tbl.getNameXPtg("ISEVEN", -1).toString());
    assertEquals(8, wrl.getRecords().size());
    // assure they are in place:
    //    [BOFRecord]
    //    [CountryRecord]
    //    [SUPBOOK Internal References  nSheets= 3]
    //    [SUPBOOK Add-In Functions nSheets= 1]
    //    [EXTERNALNAME .name    = ISODD]
    //    [EXTERNALNAME .name    = ISEVEN]
    //    [EXTERNSHEET]
    //    [EOFRecord]
    assertTrue(wrl.get(3) instanceof SupBookRecord);
    assertTrue(wrl.get(4) instanceof ExternalNameRecord);
    assertTrue(wrl.get(5) instanceof ExternalNameRecord);
    assertEquals("ISODD", ((ExternalNameRecord) wrl.get(4)).getText());
    assertEquals("ISEVEN", ((ExternalNameRecord) wrl.get(5)).getText());
    assertTrue(wrl.get(6) instanceof ExternSheetRecord);
    assertTrue(wrl.get(7) instanceof EOFRecord);
    assertEquals(0, tbl.resolveNameXIx(namex2.getSheetRefIndex(), namex2.getNameIndex()));
    assertEquals("ISEVEN", tbl.resolveNameXText(namex2.getSheetRefIndex(), namex2.getNameIndex(), null));
}
Also used : ExternalNameRecord(org.apache.poi.hssf.record.ExternalNameRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) BOFRecord(org.apache.poi.hssf.record.BOFRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord)

Aggregations

EOFRecord (org.apache.poi.hssf.record.EOFRecord)8 BOFRecord (org.apache.poi.hssf.record.BOFRecord)6 Record (org.apache.poi.hssf.record.Record)6 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)4 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)4 RecordBase (org.apache.poi.hssf.record.RecordBase)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)3 EscherRecord (org.apache.poi.ddf.EscherRecord)3 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)3 ObjRecord (org.apache.poi.hssf.record.ObjRecord)3 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)3 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)3 ArrayList (java.util.ArrayList)2 BlankRecord (org.apache.poi.hssf.record.BlankRecord)2 ColumnInfoRecord (org.apache.poi.hssf.record.ColumnInfoRecord)2 CountryRecord (org.apache.poi.hssf.record.CountryRecord)2 DateWindow1904Record (org.apache.poi.hssf.record.DateWindow1904Record)2 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)2