Search in sources :

Example 6 with RecordStream

use of org.apache.poi.hssf.model.RecordStream in project poi by apache.

the class TestCFRecordsAggregate method testCFRecordsAggregate.

public void testCFRecordsAggregate() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    List<Record> recs = new ArrayList<Record>();
    CFHeaderBase header = new CFHeaderRecord();
    CFRuleBase rule1 = CFRuleRecord.create(sheet, "7");
    CFRuleBase rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
    CFRuleBase rule3 = CFRuleRecord.create(sheet, ComparisonOperator.GE, "100", null);
    header.setNumberOfConditionalFormats(3);
    CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
    header.setCellRanges(cellRanges);
    recs.add(header);
    recs.add(rule1);
    recs.add(rule2);
    recs.add(rule3);
    CFRecordsAggregate record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
    // Serialize
    byte[] serializedRecord = new byte[record.getRecordSize()];
    record.serialize(0, serializedRecord);
    InputStream in = new ByteArrayInputStream(serializedRecord);
    //Parse
    recs = RecordFactory.createRecords(in);
    // Verify
    assertNotNull(recs);
    assertEquals(4, recs.size());
    header = (CFHeaderRecord) recs.get(0);
    rule1 = (CFRuleRecord) recs.get(1);
    assertNotNull(rule1);
    rule2 = (CFRuleRecord) recs.get(2);
    assertNotNull(rule2);
    rule3 = (CFRuleRecord) recs.get(3);
    assertNotNull(rule3);
    cellRanges = header.getCellRanges();
    assertEquals(2, cellRanges.length);
    assertEquals(3, header.getNumberOfConditionalFormats());
    assertFalse(header.getNeedRecalculation());
    record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
    record = record.cloneCFAggregate();
    assertNotNull(record.getHeader());
    assertEquals(3, record.getNumberOfRules());
    header = record.getHeader();
    rule1 = record.getRule(0);
    assertNotNull(rule1);
    rule2 = record.getRule(1);
    assertNotNull(rule2);
    rule3 = record.getRule(2);
    assertNotNull(rule3);
    cellRanges = header.getCellRanges();
    assertEquals(2, cellRanges.length);
    assertEquals(3, header.getNumberOfConditionalFormats());
    assertFalse(header.getNeedRecalculation());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) CFHeaderBase(org.apache.poi.hssf.record.CFHeaderBase) CFRuleBase(org.apache.poi.hssf.record.CFRuleBase) RecordStream(org.apache.poi.hssf.model.RecordStream) ByteArrayInputStream(java.io.ByteArrayInputStream) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Record(org.apache.poi.hssf.record.Record) CFRuleRecord(org.apache.poi.hssf.record.CFRuleRecord) CFRule12Record(org.apache.poi.hssf.record.CFRule12Record) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 7 with RecordStream

use of org.apache.poi.hssf.model.RecordStream in project poi by apache.

the class TestPageSettingsBlock method testLateMargins_bug47199.

/**
	 * Bug 47199 was due to the margin records being located well after the initial PSB records.
	 * The example file supplied (attachment 23710) had three non-PSB record types
	 * between the PRINTSETUP record and first MARGIN record:
	 * <ul>
	 * <li>PRINTSETUP(0x00A1)</li>
	 * <li>DEFAULTCOLWIDTH(0x0055)</li>
	 * <li>COLINFO(0x007D)</li>
	 * <li>DIMENSIONS(0x0200)</li>
	 * <li>BottomMargin(0x0029)</li>
	 * </ul>
	 */
public void testLateMargins_bug47199() {
    Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), createBottomMargin(0.787F), new WindowTwoRecord(), EOFRecord.instance };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    InternalSheet sheet;
    try {
        sheet = InternalSheet.createSheet(rs);
    } catch (RuntimeException e) {
        if (e.getMessage().equals("two Page Settings Blocks found in the same sheet")) {
            throw new AssertionFailedError("Identified bug 47199a - failed to process late margings records");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, 0);
    Record[] outRecs = rv.getRecords();
    // +1 for index record
    assertEquals(recs.length + 1, outRecs.length);
    assertEquals(BOFRecord.class, outRecs[0].getClass());
    assertEquals(IndexRecord.class, outRecs[1].getClass());
    assertEquals(HeaderRecord.class, outRecs[2].getClass());
    assertEquals(FooterRecord.class, outRecs[3].getClass());
    assertEquals(DimensionsRecord.class, outRecs[5].getClass());
    assertEquals(WindowTwoRecord.class, outRecs[6].getClass());
    assertEquals(EOFRecord.instance, outRecs[7]);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) AssertionFailedError(junit.framework.AssertionFailedError)

Example 8 with RecordStream

use of org.apache.poi.hssf.model.RecordStream in project poi by apache.

the class TestMergeCellsRecord method testMCTable_bug46009.

public void testMCTable_bug46009() {
    MergedCellsTable mct = new MergedCellsTable();
    List<Record> recList = new ArrayList<Record>();
    CellRangeAddress[] cras = new CellRangeAddress[] { new CellRangeAddress(0, 0, 0, 3) };
    recList.add(new MergeCellsRecord(cras, 0, 1));
    RecordStream rs = new RecordStream(recList, 0);
    mct.read(rs);
    try {
        mct.visitContainedRecords(dummyRecordVisitor);
    } catch (ArrayStoreException e) {
        throw new AssertionFailedError("Identified bug 46009");
    }
}
Also used : MergedCellsTable(org.apache.poi.hssf.record.aggregates.MergedCellsTable) RecordStream(org.apache.poi.hssf.model.RecordStream) ArrayList(java.util.ArrayList) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) AssertionFailedError(junit.framework.AssertionFailedError)

Example 9 with RecordStream

use of org.apache.poi.hssf.model.RecordStream in project poi by apache.

the class TestRowRecordsAggregate method testUnknownContinue_bug46280.

/**
	 * This problem was noted as the overt symptom of bug 46280.  The logic for skipping {@link
	 * UnknownRecord}s in the constructor {@link RowRecordsAggregate} did not allow for the
	 * possibility of tailing {@link ContinueRecord}s.<br/>
	 * The functionality change being tested here is actually not critical to the overall fix
	 * for bug 46280, since the fix involved making sure the that offending <i>PivotTable</i>
	 * records do not get into {@link RowRecordsAggregate}.<br/>
	 * This fix in {@link RowRecordsAggregate} was implemented anyway since any {@link
	 * UnknownRecord} has the potential of being 'continued'.
	 */
@Test
public void testUnknownContinue_bug46280() {
    Record[] inRecs = { new RowRecord(0), new NumberRecord(), new UnknownRecord(0x5555, "dummydata".getBytes(LocaleUtil.CHARSET_1252)), new ContinueRecord("moredummydata".getBytes(LocaleUtil.CHARSET_1252)) };
    RecordStream rs = new RecordStream(Arrays.asList(inRecs), 0);
    RowRecordsAggregate rra;
    try {
        rra = new RowRecordsAggregate(rs, SharedValueManager.createEmpty());
    } catch (RuntimeException e) {
        if (e.getMessage().startsWith("Unexpected record type")) {
            fail("Identified bug 46280a");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    rra.visitContainedRecords(rv);
    Record[] outRecs = rv.getRecords();
    assertEquals(5, outRecs.length);
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RowRecord(org.apache.poi.hssf.record.RowRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) Test(org.junit.Test)

Example 10 with RecordStream

use of org.apache.poi.hssf.model.RecordStream in project poi by apache.

the class TestValueRecordsAggregate method constructValueRecord.

private void constructValueRecord(List<Record> records) {
    RowBlocksReader rbr = new RowBlocksReader(new RecordStream(records, 0));
    SharedValueManager sfrh = rbr.getSharedFormulaManager();
    RecordStream rs = rbr.getPlainRecordStream();
    while (rs.hasNext()) {
        Record rec = rs.getNext();
        valueRecord.construct((CellValueRecordInterface) rec, rs, sfrh);
    }
}
Also used : RecordStream(org.apache.poi.hssf.model.RecordStream) RowBlocksReader(org.apache.poi.hssf.model.RowBlocksReader) Record(org.apache.poi.hssf.record.Record) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) BlankRecord(org.apache.poi.hssf.record.BlankRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord)

Aggregations

RecordStream (org.apache.poi.hssf.model.RecordStream)12 AssertionFailedError (junit.framework.AssertionFailedError)9 RecordCollector (org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector)8 InternalSheet (org.apache.poi.hssf.model.InternalSheet)5 Record (org.apache.poi.hssf.record.Record)3 ArrayList (java.util.ArrayList)2 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)2 SharedFormulaRecord (org.apache.poi.hssf.record.SharedFormulaRecord)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 RowBlocksReader (org.apache.poi.hssf.model.RowBlocksReader)1 ArrayRecord (org.apache.poi.hssf.record.ArrayRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 CFHeaderBase (org.apache.poi.hssf.record.CFHeaderBase)1 CFHeaderRecord (org.apache.poi.hssf.record.CFHeaderRecord)1 CFRule12Record (org.apache.poi.hssf.record.CFRule12Record)1 CFRuleBase (org.apache.poi.hssf.record.CFRuleBase)1 CFRuleRecord (org.apache.poi.hssf.record.CFRuleRecord)1 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)1