Esempio n. 1
0
        public void TestDuplicateHeaderFooter_bug48026()
        {
            NPOI.HSSF.Record.Record[] recs =
            {
                BOFRecord.CreateSheetBOF(),
                new IndexRecord(),

                //PageSettingsBlock
                new HeaderRecord("&LDecember"),
                new FooterRecord("&LJanuary"),
                new DimensionsRecord(),

                new WindowTwoRecord(),

                //CustomViewSettingsRecordAggregate
                new UserSViewBegin(HexRead.ReadFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")),
                new SelectionRecord(0, 0),
                new UserSViewEnd(HexRead.ReadFromString("01 00")),

                // two HeaderFooterRecord records, the first one has zero GUID (16 bytes at offset 12) and belongs to the PSB,
                // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID
                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 34 33 00 00 00 00 00 00 00 00")),
                new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")),

                EOFRecord.instance,
            };
            RecordStream  rs = new RecordStream(Arrays.AsList(recs), 0);
            InternalSheet sheet;

            try
            {
                sheet = InternalSheet.CreateSheet(rs);
            }
            catch (Exception e)
            {
                if (e.Message.Equals("Duplicate PageSettingsBlock record (sid=0x89c)"))
                {
                    throw new AssertionException("Identified bug 48026");
                }
                throw e;
            }

            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            sheet.VisitContainedRecords(rv, 0);
            NPOI.HSSF.Record.Record[] outRecs = rv.Records;

            Assert.AreEqual(recs.Length, outRecs.Length);
            //expected order of records:
            NPOI.HSSF.Record.Record[] expectedRecs =
            {
                recs[0],  //BOFRecord
                recs[1],  //IndexRecord

                //PageSettingsBlock
                recs[2],  //HeaderRecord
                recs[3],  //FooterRecord
                recs[9],  //HeaderFooterRecord
                recs[4],  // DimensionsRecord
                recs[5],  // WindowTwoRecord

                //CustomViewSettingsRecordAggregate
                recs[6],  // UserSViewBegin
                recs[7],  // SelectionRecord
                recs[10], // HeaderFooterRecord
                recs[8],  // UserSViewEnd

                recs[11], //EOFRecord
            };
            for (int i = 0; i < expectedRecs.Length; i++)
            {
                Assert.AreEqual(expectedRecs[i].GetType(), outRecs[i].GetType(), "Record mismatch at index " + i);
            }
            HeaderFooterRecord hd1 = (HeaderFooterRecord)expectedRecs[4];

            //GUID is zero
            Assert.IsTrue(Arrays.Equals(new byte[16], hd1.Guid));
            Assert.IsTrue(hd1.IsCurrentSheet);

            UserSViewBegin     svb = (UserSViewBegin)expectedRecs[7];
            HeaderFooterRecord hd2 = (HeaderFooterRecord)expectedRecs[9];

            Assert.IsFalse(hd2.IsCurrentSheet);
            //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same
            Assert.IsTrue(Arrays.Equals(svb.Guid, hd2.Guid));
        }
Esempio n. 2
0
        public CustomViewSequence(IStreamReader reader)
            : base(reader)
        {
            // CUSTOMVIEW = UserSViewBegin *Selection [HorizontalPageBreaks] [VerticalPageBreaks] [Header]
            //    [Footer] [HCenter] [VCenter] [LeftMargin] [RightMargin] [TopMargin] [BottomMargin]
            //    [Pls] [Setup] [PrintSize] [HeaderFooter] [AUTOFILTER] UserSViewEnd


            // NOTE: UserSViewBegin and UserSViewEnd seem to be optional to!


            // UserSViewBegin
            if (BiffRecord.GetNextRecordType(reader) == RecordType.UserSViewBegin)
            {
                this.UserSViewBegin = (UserSViewBegin)BiffRecord.ReadRecord(reader);
            }

            // *Selection
            this.Selections = new List <Selection>();
            while (BiffRecord.GetNextRecordType(reader) == RecordType.Selection)
            {
                this.Selections.Add((Selection)BiffRecord.ReadRecord(reader));
            }

            // [HorizontalPageBreaks]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HorizontalPageBreaks)
            {
                this.HorizontalPageBreaks = (HorizontalPageBreaks)BiffRecord.ReadRecord(reader);
            }

            // [VerticalPageBreaks]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.VerticalPageBreaks)
            {
                this.VerticalPageBreaks = (VerticalPageBreaks)BiffRecord.ReadRecord(reader);
            }

            // [Header]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Header)
            {
                this.Header = (Header)BiffRecord.ReadRecord(reader);
            }

            // [Footer]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Footer)
            {
                this.Footer = (Footer)BiffRecord.ReadRecord(reader);
            }

            // [HCenter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HCenter)
            {
                this.HCenter = (HCenter)BiffRecord.ReadRecord(reader);
            }

            // [VCenter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.VCenter)
            {
                this.VCenter = (VCenter)BiffRecord.ReadRecord(reader);
            }

            // [LeftMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.LeftMargin)
            {
                this.LeftMargin = (LeftMargin)BiffRecord.ReadRecord(reader);
            }

            // [RightMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.RightMargin)
            {
                this.RightMargin = (RightMargin)BiffRecord.ReadRecord(reader);
            }

            // [TopMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.TopMargin)
            {
                this.TopMargin = (TopMargin)BiffRecord.ReadRecord(reader);
            }

            // [BottomMargin]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.BottomMargin)
            {
                this.BottomMargin = (BottomMargin)BiffRecord.ReadRecord(reader);
            }

            // [Pls]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Pls)
            {
                this.Pls = (Pls)BiffRecord.ReadRecord(reader);
            }

            // [Setup]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.Setup)
            {
                this.Setup = (Setup)BiffRecord.ReadRecord(reader);
            }

            // [PrintSize]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.PrintSize)
            {
                this.PrintSize = (PrintSize)BiffRecord.ReadRecord(reader);
            }

            // [HeaderFooter]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.HeaderFooter)
            {
                this.HeaderFooter = (HeaderFooter)BiffRecord.ReadRecord(reader);
            }

            // [AUTOFILTER]
            if (BiffRecord.GetNextRecordType(reader) == RecordType.AutoFilterInfo)
            {
                this.AutoFilterSequence = new AutoFilterSequence(reader);
            }

            // UserSViewEnd
            if (BiffRecord.GetNextRecordType(reader) == RecordType.UserSViewEnd)
            {
                this.UserSViewEnd = (UserSViewEnd)BiffRecord.ReadRecord(reader);
            }
        }