Beispiel #1
0
 public CustomRecordVisitor1(CustomViewSettingsRecordAggregate cv, HeaderFooterRecord hf,
                             List <HeaderFooterRecord> sviewHeaderFooter, Dictionary <String, HeaderFooterRecord> hfGuidMap)
 {
     this._cv = cv;
     this._hf = hf;
     this._sviewHeaderFooters = sviewHeaderFooter;
     _hfGuidMap = hfGuidMap;
 }
Beispiel #2
0
 /// <summary>
 ///  HEADERFOOTER is new in 2007.  Some apps seem to have scattered this record long after
 /// the PageSettingsBlock where it belongs.
 /// </summary>
 /// <param name="rec"></param>
 public void AddLateHeaderFooter(HeaderFooterRecord rec)
 {
     if (_headerFooter != null)
     {
         throw new ArgumentNullException("This page settings block already has a header/footer record");
     }
     if (rec.Sid != UnknownRecord.HEADER_FOOTER_089C)
     {
         throw new RecordFormatException("Unexpected header-footer record sid: 0x" + StringUtil.ToHexString(rec.Sid));
     }
     _headerFooter = rec;
 }
Beispiel #3
0
            public void VisitRecord(Record r)
            {
                if (r.Sid == UserSViewBegin.sid)
                {
                    String             guid = HexDump.ToHex(((UserSViewBegin)r).Guid);
                    HeaderFooterRecord hf   = _hfGuidMap[guid];

                    if (hf != null)
                    {
                        {
                            _cv.Append(_hf);
                            _sviewHeaderFooters.Remove(_hf);
                        }
                    }
                }
            }
        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));
        }
Beispiel #5
0
        public InternalChart(RecordStream rs)
        {
            _plsRecords = new List <PLSAggregate>();
            records     = new List <RecordBase>(128);

            if (rs.PeekNextSid() != BOFRecord.sid)
            {
                throw new Exception("BOF record expected");
            }
            BOFRecord bof = (BOFRecord)rs.GetNext();

            if (bof.Type != BOFRecordType.Chart)
            {
                throw new RuntimeException("Bad BOF record type");
            }

            records.Add(bof);
            while (rs.HasNext())
            {
                int recSid = rs.PeekNextSid();

                Record.Record rec = rs.GetNext();
                if (recSid == EOFRecord.sid)
                {
                    records.Add(rec);
                    break;
                }

                if (recSid == ChartRecord.sid)
                {
                    continue;
                }

                if (recSid == ChartFRTInfoRecord.sid)
                {
                    _chartFrtInfo = (ChartFRTInfoRecord)rec;
                }
                else if (recSid == HeaderRecord.sid)
                {
                    header = (HeaderRecord)rec;
                }
                else if (recSid == FooterRecord.sid)
                {
                    footer = (FooterRecord)rec;
                }
                else if (recSid == HCenterRecord.sid)
                {
                    _hCenter = (HCenterRecord)rec;
                }
                else if (recSid == VCenterRecord.sid)
                {
                    _vCenter = (VCenterRecord)rec;
                }
                else if (recSid == LeftMarginRecord.sid)
                {
                    _leftMargin = (LeftMarginRecord)rec;
                }
                else if (recSid == RightMarginRecord.sid)
                {
                    _rightMargin = (RightMarginRecord)rec;
                }
                else if (recSid == TopMarginRecord.sid)
                {
                    _topMargin = (TopMarginRecord)rec;
                }
                else if (recSid == BottomMarginRecord.sid)
                {
                    _bottomMargin = (BottomMarginRecord)rec;
                }
                else if (recSid == UnknownRecord.PLS_004D) // PLS
                {
                    PLSAggregate        pls = new PLSAggregate(rs);
                    PLSAggregateVisitor rv  = new PLSAggregateVisitor(records);
                    pls.VisitContainedRecords(rv);
                    _plsRecords.Add(pls);

                    continue;
                }
                else if (recSid == PrintSetupRecord.sid)
                {
                    printSetup = (PrintSetupRecord)rec;
                }
                else if (recSid == PrintSizeRecord.sid)
                {
                    _printSize = (PrintSizeRecord)rec;
                }
                else if (recSid == HeaderFooterRecord.sid)
                {
                    HeaderFooterRecord hf = (HeaderFooterRecord)rec;
                    if (hf.IsCurrentSheet)
                    {
                        _headerFooter = hf;
                    }
                    else
                    {
                        _sviewHeaderFooters.Add(hf);
                    }
                }
                else if (recSid == ProtectRecord.sid)
                {
                    _protect = (ProtectRecord)rec;
                }
                records.Add(rec);
            }
        }
Beispiel #6
0
 public CustomRecordVisitor1(CustomViewSettingsRecordAggregate cv, HeaderFooterRecord hf, List <HeaderFooterRecord> sviewHeaderFooter)
 {
     this._cv = cv;
     this._hf = hf;
     this._sviewHeaderFooters = sviewHeaderFooter;
 }
Beispiel #7
0
        private bool ReadARecord(RecordStream rs)
        {
            switch (rs.PeekNextSid())
            {
            case HorizontalPageBreakRecord.sid:
                CheckNotPresent(_rowBreaksRecord);
                _rowBreaksRecord = (PageBreakRecord)rs.GetNext();
                break;

            case VerticalPageBreakRecord.sid:
                CheckNotPresent(_columnBreaksRecord);
                _columnBreaksRecord = (PageBreakRecord)rs.GetNext();
                break;

            case HeaderRecord.sid:
                CheckNotPresent(header);
                header = (HeaderRecord)rs.GetNext();
                break;

            case FooterRecord.sid:
                CheckNotPresent(footer);
                footer = (FooterRecord)rs.GetNext();
                break;

            case HCenterRecord.sid:
                CheckNotPresent(_hCenter);
                _hCenter = (HCenterRecord)rs.GetNext();
                break;

            case VCenterRecord.sid:
                CheckNotPresent(_vCenter);
                _vCenter = (VCenterRecord)rs.GetNext();
                break;

            case LeftMarginRecord.sid:
                CheckNotPresent(_leftMargin);
                _leftMargin = (LeftMarginRecord)rs.GetNext();
                break;

            case RightMarginRecord.sid:
                CheckNotPresent(_rightMargin);
                _rightMargin = (RightMarginRecord)rs.GetNext();
                break;

            case TopMarginRecord.sid:
                CheckNotPresent(_topMargin);
                _topMargin = (TopMarginRecord)rs.GetNext();
                break;

            case BottomMarginRecord.sid:
                CheckNotPresent(_bottomMargin);
                _bottomMargin = (BottomMarginRecord)rs.GetNext();
                break;

            case UnknownRecord.PLS_004D:     // PLS
                _plsRecords.Add(new PLSAggregate(rs));
                break;

            case PrintSetupRecord.sid:
                CheckNotPresent(printSetup);
                printSetup = (PrintSetupRecord)rs.GetNext();
                break;

            case UnknownRecord.BITMAP_00E9:     // BITMAP
                CheckNotPresent(_bitmap);
                _bitmap = rs.GetNext();
                break;

            case UnknownRecord.PRINTSIZE_0033:
                CheckNotPresent(_printSize);
                _printSize = rs.GetNext();
                break;

            case HeaderFooterRecord.sid:
                HeaderFooterRecord hf = (HeaderFooterRecord)rs.GetNext();
                if (hf.IsCurrentSheet)
                {
                    _headerFooter = hf;
                }
                else
                {
                    _sviewHeaderFooters.Add(hf);
                }
                break;

            default:
                // all other record types are not part of the PageSettingsBlock
                return(false);
            }
            return(true);
        }