Search in sources :

Example 51 with Record

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

the class HSSFSheet method getDataValidations.

@Override
public List<HSSFDataValidation> getDataValidations() {
    DataValidityTable dvt = _sheet.getOrCreateDataValidityTable();
    final List<HSSFDataValidation> hssfValidations = new ArrayList<HSSFDataValidation>();
    RecordVisitor visitor = new RecordVisitor() {

        private HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(getWorkbook());

        @Override
        public void visitRecord(Record r) {
            if (!(r instanceof DVRecord)) {
                return;
            }
            DVRecord dvRecord = (DVRecord) r;
            CellRangeAddressList regions = dvRecord.getCellRangeAddress().copy();
            DVConstraint constraint = DVConstraint.createDVConstraint(dvRecord, book);
            HSSFDataValidation hssfDataValidation = new HSSFDataValidation(regions, constraint);
            hssfDataValidation.setErrorStyle(dvRecord.getErrorStyle());
            hssfDataValidation.setEmptyCellAllowed(dvRecord.getEmptyCellAllowed());
            hssfDataValidation.setSuppressDropDownArrow(dvRecord.getSuppressDropdownArrow());
            hssfDataValidation.createPromptBox(dvRecord.getPromptTitle(), dvRecord.getPromptText());
            hssfDataValidation.setShowPromptBox(dvRecord.getShowPromptOnCellSelected());
            hssfDataValidation.createErrorBox(dvRecord.getErrorTitle(), dvRecord.getErrorText());
            hssfDataValidation.setShowErrorBox(dvRecord.getShowErrorOnInvalidValue());
            hssfValidations.add(hssfDataValidation);
        }
    };
    dvt.visitContainedRecords(visitor);
    return hssfValidations;
}
Also used : DVRecord(org.apache.poi.hssf.record.DVRecord) ArrayList(java.util.ArrayList) SCLRecord(org.apache.poi.hssf.record.SCLRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) Record(org.apache.poi.hssf.record.Record) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) DVRecord(org.apache.poi.hssf.record.DVRecord) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) DataValidityTable(org.apache.poi.hssf.record.aggregates.DataValidityTable) RecordVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor)

Example 52 with Record

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

the class HSSFSheet method setPropertiesFromSheet.

/**
     * used internally to set the properties given a Sheet object
     */
private void setPropertiesFromSheet(InternalSheet sheet) {
    RowRecord row = sheet.getNextRow();
    while (row != null) {
        createRowFromRecord(row);
        row = sheet.getNextRow();
    }
    Iterator<CellValueRecordInterface> iter = sheet.getCellValueIterator();
    long timestart = System.currentTimeMillis();
    if (log.check(POILogger.DEBUG)) {
        log.log(DEBUG, "Time at start of cell creating in HSSF sheet = ", Long.valueOf(timestart));
    }
    HSSFRow lastrow = null;
    // Add every cell to its row
    while (iter.hasNext()) {
        CellValueRecordInterface cval = iter.next();
        long cellstart = System.currentTimeMillis();
        HSSFRow hrow = lastrow;
        if (hrow == null || hrow.getRowNum() != cval.getRow()) {
            hrow = getRow(cval.getRow());
            lastrow = hrow;
            if (hrow == null) {
                /* we removed this check, see bug 47245 for the discussion around this
                    // Some tools (like Perl module Spreadsheet::WriteExcel - bug 41187) skip the RowRecords
                    // Excel, OpenOffice.org and GoogleDocs are all OK with this, so POI should be too.
                    if (rowRecordsAlreadyPresent) {
                        // if at least one row record is present, all should be present.
                        throw new RuntimeException("Unexpected missing row when some rows already present");
                    }*/
                // create the row record on the fly now.
                RowRecord rowRec = new RowRecord(cval.getRow());
                sheet.addRow(rowRec);
                hrow = createRowFromRecord(rowRec);
            }
        }
        if (log.check(POILogger.DEBUG)) {
            if (cval instanceof Record) {
                log.log(DEBUG, "record id = " + Integer.toHexString(((Record) cval).getSid()));
            } else {
                log.log(DEBUG, "record = " + cval);
            }
        }
        hrow.createCellFromRecord(cval);
        if (log.check(POILogger.DEBUG)) {
            log.log(DEBUG, "record took ", Long.valueOf(System.currentTimeMillis() - cellstart));
        }
    }
    if (log.check(POILogger.DEBUG)) {
        log.log(DEBUG, "total sheet cell creation took ", Long.valueOf(System.currentTimeMillis() - timestart));
    }
}
Also used : CellValueRecordInterface(org.apache.poi.hssf.record.CellValueRecordInterface) RowRecord(org.apache.poi.hssf.record.RowRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) Record(org.apache.poi.hssf.record.Record) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) DVRecord(org.apache.poi.hssf.record.DVRecord)

Example 53 with Record

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

the class TestDrawingAggregate method test45129.

/**
     * test reading drawing aggregate from a test file from Bugzilla 45129
     */
@Test
public void test45129() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45129.xls");
    HSSFSheet sh = wb.getSheetAt(0);
    InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
    InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
    List<RecordBase> records = isheet.getRecords();
    // the sheet's drawing is not aggregated
    assertEquals("wrong size of sheet records stream", 394, records.size());
    // the last record before the drawing block
    assertTrue("records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(), records.get(18) instanceof RowRecordsAggregate);
    // records to be aggregated
    List<RecordBase> dgRecords = records.subList(19, 389);
    // collect drawing records into a byte buffer.
    byte[] dgBytes = toByteArray(dgRecords);
    for (RecordBase rb : dgRecords) {
        Record r = (Record) rb;
        short sid = r.getSid();
        // we expect that drawing block consists of either
        // DrawingRecord or ContinueRecord or ObjRecord or TextObjectRecord
        assertTrue(sid == DrawingRecord.sid || sid == ContinueRecord.sid || sid == ObjRecord.sid || sid == TextObjectRecord.sid);
    }
    // the first record after the drawing block
    assertTrue("records.get(389) is expected to be Window2", records.get(389) instanceof WindowTwoRecord);
    // aggregate drawing records.
    // The subrange [19, 388] is expected to be replaced with a EscherAggregate object
    DrawingManager2 drawingManager = iworkbook.findDrawingGroup();
    int loc = isheet.aggregateDrawingRecords(drawingManager, false);
    EscherAggregate agg = (EscherAggregate) records.get(loc);
    assertEquals("wrong size of the aggregated sheet records stream", 25, records.size());
    assertTrue("records.get(18) is expected to be RowRecordsAggregate but was " + records.get(18).getClass().getSimpleName(), records.get(18) instanceof RowRecordsAggregate);
    assertTrue("records.get(19) is expected to be EscherAggregate but was " + records.get(19).getClass().getSimpleName(), records.get(19) instanceof EscherAggregate);
    assertTrue("records.get(20) is expected to be Window2 but was " + records.get(20).getClass().getSimpleName(), records.get(20) instanceof WindowTwoRecord);
    byte[] dgBytesAfterSave = agg.serialize();
    assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
    assertTrue("drawing data before and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
    wb.close();
}
Also used : WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) RowRecordsAggregate(org.apache.poi.hssf.record.aggregates.RowRecordsAggregate) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordBase(org.apache.poi.hssf.record.RecordBase) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) Test(org.junit.Test)

Example 54 with Record

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

the class TestDrawingAggregate method testUnhandledContinue.

@Test
public void testUnhandledContinue() throws IOException {
    String data = "H4sIAAAAAAAAAO3adVRU2/4A8EPHAEOnlEooNaSUdCNIg4CUDCEtQ6gwlITSjYiSkoKA0ikg0i1IyCjS" + "QwpSEr8B73v3PS6+9+67vz/eH+615pyz9tn71PqevT/rfGcJOIcLBtDXrNgAgBjAXcMFAAAb9SPDBAAw" + "gLGmzna8xlxjR9WhAXhrxMAfCzqAf9IPQPXBAn6078IBgAyCH/VgVD2ADwCxAGhNBbXpc9LUF2h8n4we" + "iOoNAKEnywaAFmAEGtDQABLgCA0AcAHfZvLjeozjc+gAUMATgAEygBNqzQTwHl8lcH5dGHWmvGY+1FJD" + "FQOTHHX1x+dkBta2H9UcoLam0I7bAYCRrJMjDOoIM9W56wx1vcnt6WAfF92t0gIhfrfqv0o8e9khH4fE" + "thqnQJHiJqOZUrbDByG8xwYeiEmYJPcUPoP17NH6hTz9cVtyfvnyyUuV3BzE06+vDH/Dlxi+/pYeV32e" + "IGIy2p+e90VyZ+i9OlDL+Rp6Dmot/G2tUgYbGW5vpkSep5Fk2eKtJthDdEvKkzrvC4cmWe7kKaliC7ip" + "0sMjlMUdN/akSG0ticE4nweeA7LUha1xyjNLXZEJUx80rOZMmg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flEnxnPxcax9scj" + "lToDBcO0pj5X3t7kifqSPfmyOjC8dKfK1GBAJ0ydvb8WSyv18/6Vwdj9aYKeNLT1q7nMXLlgkoOFNqzE" + "2nm7cSKRT4xtUp10hOZfm4YE0Ypt3Z/MaGB/DmqcUQt5RHWUzfTQJS21R/ToZnLorfPzIZocgeD19QPw" + "XHTIFdwHg7Mlmota6OqYilolxSmSlx8CKjwsELJHKCrINvmNCxi34NV87Ipn6YNICQjQvqAz/rKMznR+" + "xLnkeisDE8nNYUGNo/Yd6z5nn79bwVxU+VrjMw6FYyvsRHjKviTE8i3z9Tag580i9Ern5SnETqo8xEsw" + "fIyRKSNIzwJRMUUgiRI8wm5TB8UZvJzFngq0eBhAJRO5vbBiKg5703eOV45AT6Sh6XK9gDG76nyVal0a" + "GR0lk4aLl1kWQ6H+WmNtU1jngMZR7RpLTy8JgWWcC6Gelj7Icfervb2pQuc3RKswbdDSUy3K1mwMB09O" + "lBZ8Pj1LRWmBn0xd0b0TcWaMvhRwTruEejUL/yMtjCZxXMuKevsgpH2fOmbNcDiBq2jZnuNYC7lyjL3W" + "qwueYx20DlUl8XqYe3XExPqBVvFjxAb1PUWkUsOab20KKdiK5yizYzde8dLz1mmLILgnsHdJoYpxUgvG" + "/PjoRnHGWuODhPomZGNKi+ICT3xpqjdmSokyIOcwY/Q6GjQGghDxtZ5GXkroNGSRBZXJVzXWn/V8EX8z" + "bh2EV1VrM2gkFVGxYum4qEsJHd2DPj6kJnJzVTADlCZWR7ItRI7zEPBUU2RiU8t1G6QOxXMhpekJvVQ4" + "IppKQdVys+cLtUY6Un0+hI2Z0wMzAxO8Lr0LbaILk8WtNsxpaFYMrTjC22723OH5GFkUi+ux8An2Hi0F" + "fvcr1v8aFU6POn+OCqfj4ffS/e+pcOEMKhABrCdUAAPhwB+pQHYGFcT/BBUEz6LC/wGpc+eRNSkAAA==";
    byte[] dgBytes = decompress(data);
    List<Record> dgRecords = RecordFactory.createRecords(new ByteArrayInputStream(dgBytes));
    assertEquals(20, dgRecords.size());
    short[] expectedSids = { DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, TextObjectRecord.sid, DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, TextObjectRecord.sid, DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, TextObjectRecord.sid, DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, TextObjectRecord.sid, ContinueRecord.sid, ObjRecord.sid, ContinueRecord.sid, TextObjectRecord.sid };
    for (int i = 0; i < expectedSids.length; i++) {
        assertEquals("unexpected record.sid and index[" + i + "]", expectedSids[i], dgRecords.get(i).getSid());
    }
    DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord());
    // create a dummy sheet consisting of our test data
    InternalSheet sheet = InternalSheet.createSheet();
    List<RecordBase> records = sheet.getRecords();
    records.clear();
    records.addAll(dgRecords);
    records.add(EOFRecord.instance);
    sheet.aggregateDrawingRecords(drawingManager, false);
    assertEquals("drawing was not fully aggregated", 2, records.size());
    assertTrue("expected EscherAggregate", records.get(0) instanceof EscherAggregate);
    assertTrue("expected EOFRecord", records.get(1) instanceof EOFRecord);
    EscherAggregate agg = (EscherAggregate) records.get(0);
    byte[] dgBytesAfterSave = agg.serialize();
    assertEquals("different size of drawing data before and after save", dgBytes.length, dgBytesAfterSave.length);
    assertTrue("drawing data before and after save is different", Arrays.equals(dgBytes, dgBytesAfterSave));
}
Also used : EOFRecord(org.apache.poi.hssf.record.EOFRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) ByteArrayInputStream(java.io.ByteArrayInputStream) RecordBase(org.apache.poi.hssf.record.RecordBase) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) Test(org.junit.Test)

Example 55 with Record

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

the class TestEventRecordFactory method testContinuedUnknownRecord.

/**
     * TEST NAME:  Test Creating ContinueRecords After Unknown Records From An InputStream <P>
     * OBJECTIVE:  Test that the RecordFactory given an InputStream
     *             constructs the expected records.<P>
     * SUCCESS:    Record factory creates the expected records.<P>
     * FAILURE:    The wrong records are created or contain the wrong values <P>
     *
     */
public void testContinuedUnknownRecord() {
    final byte[] data = { // an unknown record with 0 length
    0, // an unknown record with 0 length
    -1, // an unknown record with 0 length
    0, // an unknown record with 0 length
    0, // a continuation record with 3 bytes of data
    0x3C, // a continuation record with 3 bytes of data
    0, // a continuation record with 3 bytes of data
    3, // a continuation record with 3 bytes of data
    0, // a continuation record with 3 bytes of data
    1, // a continuation record with 3 bytes of data
    2, // a continuation record with 3 bytes of data
    3, // one more continuation record with 1 byte of data
    0x3C, // one more continuation record with 1 byte of data
    0, // one more continuation record with 1 byte of data
    1, // one more continuation record with 1 byte of data
    0, // one more continuation record with 1 byte of data
    4 };
    final int[] recCnt = { 0 };
    final int[] offset = { 0 };
    ERFListener listener = new ERFListener() {

        private final String[] expectedRecordTypes = { UnknownRecord.class.getName(), ContinueRecord.class.getName(), ContinueRecord.class.getName() };

        @Override
        public boolean processRecord(Record rec) {
            // System.out.println(rec.toString());
            assertEquals("Record type", expectedRecordTypes[recCnt[0]], rec.getClass().getName());
            compareData(rec, "Record " + recCnt[0] + ": ");
            recCnt[0]++;
            return true;
        }

        private void compareData(Record record, String message) {
            byte[] recData = record.serialize();
            for (int i = 0; i < recData.length; i++) {
                assertEquals(message + " data byte " + i, data[offset[0]++], recData[i]);
            }
        }
    };
    EventRecordFactory factory = new EventRecordFactory(listener, new short[] { -256, 0x3C });
    factory.processRecords(new ByteArrayInputStream(data));
    assertEquals("nr. of processed records", 3, recCnt[0]);
    assertEquals("nr. of processed bytes", data.length, offset[0]);
}
Also used : 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)

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