public void TestBiffRecordCloneAndGetBytes()
        {
            BoundSheet8 bs8 = new BoundSheet8(BoundSheet8.HiddenState.Visible, BoundSheet8.SheetType.Worksheet, "MySheetName");

            byte[]     bs8bytes       = bs8.GetBytes();
            BiffRecord bs8CloneRecord = (BiffRecord)bs8.Clone();

            byte[] bs8cloneBytes = bs8CloneRecord.GetBytes();
            Assert.AreEqual(bs8bytes, bs8cloneBytes);
            BoundSheet8 bs8Clone = bs8CloneRecord.AsRecordType <BoundSheet8>();

            byte[] bs8asRecordBytes = bs8Clone.GetBytes();
            Assert.AreEqual(bs8bytes, bs8asRecordBytes);
        }
Esempio n. 2
0
        public void TestAddingSheetRecord()
        {
            byte[]         wbBytes = TestHelpers.GetTemplateMacroBytes();
            WorkbookStream wbs     = new WorkbookStream(wbBytes);

            BoundSheet8 bs8 = new BoundSheet8(BoundSheet8.HiddenState.Visible, BoundSheet8.SheetType.Macrosheet, "MyMacroSheet");
            BoundSheet8 correctOffsetBs8 = ((BiffRecord)bs8.Clone()).AsRecordType <BoundSheet8>();

            BoundSheet8 oldSheetRecord = wbs.GetAllRecordsByType <BoundSheet8>().First();
            BoundSheet8 newSheetRecord = ((BiffRecord)oldSheetRecord.Clone()).AsRecordType <BoundSheet8>();

            // bs8.lbPlyPos = (uint) (oldSheetRecord.lbPlyPos + bs8.GetBytes().Length);

            List <BOF> bofRecords     = wbs.GetAllRecordsByType <BOF>();
            BOF        spreadSheetBOF = bofRecords.Last();



            // newSheetRecord.lbPlyPos = bs8.lbPlyPos;
            long offset = wbs.GetRecordByteOffset(spreadSheetBOF);

            bs8.lbPlyPos = oldSheetRecord.lbPlyPos;
            wbs          = wbs.InsertRecord(bs8, oldSheetRecord);
            offset       = wbs.GetRecordByteOffset(spreadSheetBOF);


            correctOffsetBs8.lbPlyPos = (uint)offset;
            newSheetRecord.lbPlyPos   = (uint)offset;

            wbs = wbs.ReplaceRecord(bs8, correctOffsetBs8);
            wbs = wbs.ReplaceRecord(oldSheetRecord, newSheetRecord);

            ExcelDocWriter writer = new ExcelDocWriter();

            writer.WriteDocument(TestHelpers.AssemblyDirectory + Path.DirectorySeparatorChar + "testbook.xls", wbs.ToBytes());
        }