Search in sources :

Example 6 with RecordBase

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

the class HSSFChart method removeSeries.

public boolean removeSeries(HSSFSeries remSeries) {
    int deep = 0;
    int chartDeep = -1;
    int lastSeriesDeep = -1;
    int seriesIdx = -1;
    boolean removeSeries = false;
    boolean chartEntered = false;
    boolean result = false;
    final List<RecordBase> records = sheet.getSheet().getRecords();
    /* store first series as template and find last series index */
    Iterator<RecordBase> iter = records.iterator();
    while (iter.hasNext()) {
        RecordBase record = iter.next();
        if (record instanceof BeginRecord) {
            deep++;
        } else if (record instanceof EndRecord) {
            deep--;
            if (lastSeriesDeep == deep) {
                lastSeriesDeep = -1;
                if (removeSeries) {
                    removeSeries = false;
                    result = true;
                    iter.remove();
                }
            }
            if (chartDeep == deep) {
                break;
            }
        }
        if (record instanceof ChartRecord) {
            if (record == chartRecord) {
                chartDeep = deep;
                chartEntered = true;
            }
        } else if (record instanceof SeriesRecord) {
            if (chartEntered) {
                if (remSeries.series == record) {
                    lastSeriesDeep = deep;
                    removeSeries = true;
                } else {
                    seriesIdx++;
                }
            }
        } else if (record instanceof DataFormatRecord) {
            if (chartEntered && !removeSeries) {
                DataFormatRecord dataFormatRecord = (DataFormatRecord) record;
                dataFormatRecord.setSeriesIndex((short) seriesIdx);
                dataFormatRecord.setSeriesNumber((short) seriesIdx);
            }
        }
        if (removeSeries) {
            iter.remove();
        }
    }
    return result;
}
Also used : EndRecord(org.apache.poi.hssf.record.chart.EndRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) BeginRecord(org.apache.poi.hssf.record.chart.BeginRecord) DataFormatRecord(org.apache.poi.hssf.record.chart.DataFormatRecord) ChartRecord(org.apache.poi.hssf.record.chart.ChartRecord) SeriesRecord(org.apache.poi.hssf.record.chart.SeriesRecord)

Example 7 with RecordBase

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

the class TestDrawingAggregate method testSerializeDrawingBigger8k_noAggregation.

@Test
public void testSerializeDrawingBigger8k_noAggregation() throws IOException {
    HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
    InternalSheet isheet = HSSFTestHelper.getSheetForTest(wb1.getSheetAt(0));
    List<RecordBase> records = isheet.getRecords();
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    InternalSheet isheet2 = HSSFTestHelper.getSheetForTest(wb2.getSheetAt(0));
    List<RecordBase> records2 = isheet2.getRecords();
    assertEquals(records.size(), records2.size());
    for (int i = 0; i < records.size(); i++) {
        RecordBase r1 = records.get(i);
        RecordBase r2 = records2.get(i);
        assertTrue(r1.getClass() == r2.getClass());
        assertEquals(r1.getRecordSize(), r2.getRecordSize());
        if (r1 instanceof Record) {
            assertEquals(((Record) r1).getSid(), ((Record) r2).getSid());
            assertArrayEquals(((Record) r1).serialize(), ((Record) r2).serialize());
        }
    }
    wb2.close();
}
Also used : 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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 8 with RecordBase

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

the class TestDrawingAggregate method testUnhandledContinue2.

@Test
public void testUnhandledContinue2() throws IOException {
    String data = "H4sIAAAAAAAAAO3bdVRUW9sA8AGGrqFHSlpAhSEcQAkJ6UYQyaFBmiEFpCVEOiREGikJSek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qGy+fo0caYztLvt5inEq5VDSzV+2TRLc0Vn9ne12i" + "4lY8ar4nviaKEVyUl4u5tPzLIU0JNEfhE8lZUWw72xT81yoD4mVICkRB6fG/U6DsfynQeUIBLWX30o6a" + "qfVQileiZT0plgOsMk1JVdN2CfnpkWQBVrsO532MLkWjW8bOkRKMN3JX12sVVynXye/ds7yIGShNwoNT" + "Xq4rH9RlyfEo4WmYXEGsLK6pyocQ0sRtfp2yVpeJCKy30uPKz8NE3gkeTx5h6XziEObeJvWsj6opUHpX" + "8xQ7myirkq/lAxH1K0x3m6MMPnT0z1rPCPVfsKmaXnpHCiG43wKLSH2fpttVq3G3Nl4LWyr/SHo+Lwvi" + "p9IQmzVDjm0LdSLqeHM8ILiJRsdoNYS93WyEhi7IOdKXZLTCvCLifxTMEi+snNzAtfevk8DpkejvSeB0" + "BPza/oPKABD5z4SARKQEELP1WQsFMc+QwP8ATkmhK404AAA=";
    byte[] dgBytes = decompress(data);
    List<Record> dgRecords = RecordFactory.createRecords(new ByteArrayInputStream(dgBytes));
    assertEquals(14, dgRecords.size());
    short[] expectedSids = { DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, ObjRecord.sid, DrawingRecord.sid, ObjRecord.sid, ContinueRecord.sid, ObjRecord.sid, ContinueRecord.sid, ObjRecord.sid, ContinueRecord.sid, ObjRecord.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 brefpore 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 9 with RecordBase

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

the class TestDrawingAggregate method testSolverContainerMustBeSavedDuringSerialization.

@Test
public void testSolverContainerMustBeSavedDuringSerialization() throws IOException {
    HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("SolverContainerAfterSPGR.xls");
    HSSFSheet sh = wb1.getSheetAt(0);
    InternalSheet ish = HSSFTestHelper.getSheetForTest(sh);
    List<RecordBase> records = ish.getRecords();
    // records to be aggregated
    List<RecordBase> dgRecords = records.subList(19, 22);
    byte[] dgBytes = toByteArray(dgRecords);
    sh.getDrawingPatriarch();
    EscherAggregate agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
    assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
    assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sh = wb2.getSheetAt(0);
    sh.getDrawingPatriarch();
    ish = HSSFTestHelper.getSheetForTest(sh);
    agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
    assertEquals(agg.getEscherRecords().get(0).getChildRecords().size(), 3);
    assertEquals(agg.getEscherRecords().get(0).getChild(2).getRecordId(), EscherContainerRecord.SOLVER_CONTAINER);
    // collect drawing records into a byte buffer.
    agg = (EscherAggregate) ish.findFirstRecordBySid(EscherAggregate.sid);
    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));
    wb2.close();
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordBase(org.apache.poi.hssf.record.RecordBase) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 10 with RecordBase

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

the class TestDrawingAggregate method testSerializeDrawingBigger8k.

/**
     * Try to check file with such record sequence
     * ...
     * DrawingRecord
     * ContinueRecord
     * ObjRecord | TextObjRecord
     * ...
     */
@Test
public void testSerializeDrawingBigger8k() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
    InternalWorkbook iworkbook = HSSFTestHelper.getWorkbookForTest(wb);
    HSSFSheet sh = wb.getSheetAt(0);
    InternalSheet isheet = HSSFTestHelper.getSheetForTest(sh);
    List<RecordBase> records = isheet.getRecords();
    // the sheet's drawing is not aggregated
    assertEquals("wrong size of sheet records stream", 32, 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, 26);
    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 == NoteRecord.sid || sid == TextObjectRecord.sid);
    }
    // collect drawing records into a byte buffer.
    byte[] dgBytes = toByteArray(dgRecords);
    // the first record after the drawing block
    assertTrue("records.get(26) is expected to be Window2", records.get(26) instanceof WindowTwoRecord);
    // aggregate drawing records.
    // The subrange [19, 38] 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", 26, 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)

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