Search in sources :

Example 11 with RecordStream

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

the class TestPageSettingsBlock method testHeaderFooter_bug46840.

/**
	 * Bug 46840 occurred because POI failed to recognise HEADERFOOTER as part of the
	 * {@link PageSettingsBlock}.
	 */
public void testHeaderFooter_bug46840() {
    int rowIx = 5;
    int colIx = 6;
    NumberRecord nr = new NumberRecord();
    nr.setRow(rowIx);
    nr.setColumn((short) colIx);
    nr.setValue(3.0);
    Record[] recs = { BOFRecord.createSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), new DimensionsRecord(), new WindowTwoRecord(), new UserSViewBegin(HexRead.readFromString("ED 77 3B 86 BC 3F 37 4C A9 58 60 23 43 68 54 4B 01 00 00 00 64 00 00 00 40 00 00 00 02 00 00 00 3D 80 04 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0 3F FF FF 01 00")), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new HeaderFooterRecord(HexRead.readFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), new UserSViewEnd(HexRead.readFromString("01, 00")), 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 46480");
        }
        throw e;
    }
    RecordCollector rv = new RecordCollector();
    sheet.visitContainedRecords(rv, rowIx);
    Record[] outRecs = rv.getRecords();
    assertEquals(13, outRecs.length);
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) InternalSheet(org.apache.poi.hssf.model.InternalSheet) AssertionFailedError(junit.framework.AssertionFailedError)

Example 12 with RecordStream

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

the class TestPageSettingsBlock method testDuplicatePLS_bug47415.

/**
	 * Apparently it's OK to have more than one PLS record.
	 * Attachment 23866 from bug 47415 had a PageSettingsBlock with two PLS records.  This file
	 * seems to open OK in Excel(2007) but both PLS records are removed (perhaps because the
	 * specified printers were not available on the testing machine).  Since the example file does
	 * not upset Excel, POI will preserve multiple PLS records.</p>
	 *
	 * As of June 2009, PLS is still uninterpreted by POI
	 */
public void testDuplicatePLS_bug47415() {
    Record plsA = ur(UnknownRecord.PLS_004D, "BA AD F0 0D");
    Record plsB = ur(UnknownRecord.PLS_004D, "DE AD BE EF");
    Record contB1 = new ContinueRecord(HexRead.readFromString("FE ED"));
    Record contB2 = new ContinueRecord(HexRead.readFromString("FA CE"));
    Record[] recs = { new HeaderRecord("&LSales Figures"), new FooterRecord("&LInventory"), new HCenterRecord(), new VCenterRecord(), plsA, // make sure continuing PLS is still OK
    plsB, // make sure continuing PLS is still OK
    contB1, // make sure continuing PLS is still OK
    contB2 };
    RecordStream rs = new RecordStream(Arrays.asList(recs), 0);
    PageSettingsBlock psb;
    try {
        psb = new PageSettingsBlock(rs);
    } catch (org.apache.poi.util.RecordFormatException e) {
        if ("Duplicate PageSettingsBlock record (sid=0x4d)".equals(e.getMessage())) {
            throw new AssertionFailedError("Identified bug 47415");
        }
        throw e;
    }
    // serialize the PSB to see what records come out
    RecordCollector rc = new RecordCollector();
    psb.visitContainedRecords(rc);
    Record[] outRecs = rc.getRecords();
    // records were assembled in standard order, so this simple check is OK
    assertArrayEquals(recs, outRecs);
}
Also used : RecordCollector(org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector) RecordStream(org.apache.poi.hssf.model.RecordStream) AssertionFailedError(junit.framework.AssertionFailedError)

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