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);
}
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);
}
Aggregations