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