public WorkbookStream AddLabel(string label, Stack <AbstractPtg> rgce, bool isMacroStack = false) { /* * Labels require a reference to an XTI index which is used to say which * BoundSheet8 record maps to the appropriate tab. In order to make this * record we need a SupBook record, and ExternSheet record to specify * which BoundSheet8 record to use. * * Currently this assumes there are no SupBook or ExternSheet records in * use, handling of these cases for complex decoy docs is coming * in the future. * * TODO handle existing SupBook/ExternSheet records when adding Lbl entries */ List <BoundSheet8> sheets = WbStream.GetAllRecordsByType <BoundSheet8>(); List <SupBook> supBooksExisting = WbStream.GetAllRecordsByType <SupBook>(); List <ExternSheet> externSheetsExisting = WbStream.GetAllRecordsByType <ExternSheet>(); ExternSheet lastExternSheet; if (supBooksExisting.Count > 0 || externSheetsExisting.Count > 0) { lastExternSheet = externSheetsExisting.Last(); } else { BiffRecord lastCountryRecord = WbStream.GetAllRecordsByType <Country>().Last(); SupBook supBookRecord = new SupBook(sheets.Count, 0x401); int macroOffset = sheets.TakeWhile(s => s.dt != BoundSheet8.SheetType.Macrosheet).Count(); ExternSheet externSheetRecord = new ExternSheet(1, new List <XTI>() { new XTI(0, macroOffset, macroOffset) }); WbStream = WbStream.InsertRecord(supBookRecord, lastCountryRecord); WbStream = WbStream.InsertRecord(externSheetRecord, supBookRecord); lastExternSheet = externSheetRecord; } Lbl newLbl = new Lbl(label, 0); if (isMacroStack) { newLbl.fProc = true; newLbl.fFunc = true; } newLbl.SetRgce(rgce); WbStream = WbStream.InsertRecord(newLbl, lastExternSheet); WbStream = WbStream.FixBoundSheetOffsets(); return(WbStream); }
public WorkbookStream AddLabel(string label, int rw, int col) { /* * Labels require a reference to an XTI index which is used to say which * BoundSheet8 record maps to the appropriate tab. In order to make this * record we need a SupBook record, and ExternSheet record to specify * which BoundSheet8 record to use. * * Currently this assumes there are no SupBook or ExternSheet records in * use, handling of these cases for complex decoy docs is coming * in the future. * * TODO handle existing SupBook/ExternSheet records when adding Lbl entries */ List <BoundSheet8> sheets = WbStream.GetAllRecordsByType <BoundSheet8>(); List <SupBook> supBooksExisting = WbStream.GetAllRecordsByType <SupBook>(); List <ExternSheet> externSheetsExisting = WbStream.GetAllRecordsByType <ExternSheet>(); if (supBooksExisting.Count > 0 || externSheetsExisting.Count > 0) { throw new NotImplementedException("Use a Decoy Document with no Labels"); } BiffRecord lastCountryRecord = WbStream.GetAllRecordsByType <Country>().Last(); SupBook supBookRecord = new SupBook(sheets.Count, 0x401); int macroOffset = sheets.TakeWhile(s => s.dt != BoundSheet8.SheetType.Macrosheet).Count(); ExternSheet externSheetRecord = new ExternSheet(1, new List <XTI>() { new XTI(0, macroOffset, macroOffset) }); Stack <AbstractPtg> ptgStack = new Stack <AbstractPtg>(); ptgStack.Push(new PtgRef3d(rw, col, 0)); Lbl newLbl = new Lbl(label, 0); newLbl.SetRgce(ptgStack); WbStream = WbStream.InsertRecord(supBookRecord, lastCountryRecord); WbStream = WbStream.InsertRecord(externSheetRecord, supBookRecord); WbStream = WbStream.InsertRecord(newLbl, externSheetRecord); WbStream = WbStream.FixBoundSheetOffsets(); return(WbStream); }
public WorkbookStream AddLabel(string label, Stack <AbstractPtg> rgce, bool isHidden = false, bool isUnicode = false, bool isMacroStack = false) { /* * Labels require a reference to an XTI index which is used to say which * BoundSheet8 record maps to the appropriate tab. In order to make this * record we need a SupBook record, and ExternSheet record to specify * which BoundSheet8 record to use. * * Currently this assumes there are no SupBook or ExternSheet records in * use, handling of these cases for complex decoy docs is coming * in the future. * * TODO handle existing SupBook/ExternSheet records when adding Lbl entries */ List <SupBook> supBooksExisting = WbStream.GetAllRecordsByType <SupBook>(); List <ExternSheet> externSheetsExisting = WbStream.GetAllRecordsByType <ExternSheet>(); List <Lbl> existingLbls = WbStream.GetAllRecordsByType <Lbl>(); ExternSheet lastExternSheet; if (supBooksExisting.Count > 0 || externSheetsExisting.Count > 0) { lastExternSheet = externSheetsExisting.Last(); } else { InitializeGlobalStreamLabels(); lastExternSheet = WbStream.GetAllRecordsByType <ExternSheet>().Last();; } Lbl newLbl = new Lbl(label, 0); if (isUnicode) { newLbl.SetName(new XLUnicodeStringNoCch(label, true)); } if (isMacroStack) { newLbl.fProc = true; newLbl.fFunc = true; } if (isHidden) { newLbl.fHidden = true; } if (rgce != null) { newLbl.SetRgce(rgce); } else { newLbl.cce = 0; } if (existingLbls.Count > 0) { WbStream = WbStream.InsertRecord(newLbl, existingLbls.Last()); } else { WbStream = WbStream.InsertRecord(newLbl, lastExternSheet); } WbStream = WbStream.FixBoundSheetOffsets(); return(WbStream); }
public WorkbookStream AddLabel(string label, Stack <AbstractPtg> rgce, bool isHidden = false, bool isUnicode = false, bool isMacroStack = false) { /* * Labels require a reference to an XTI index which is used to say which * BoundSheet8 record maps to the appropriate tab. In order to make this * record we need a SupBook record, and ExternSheet record to specify * which BoundSheet8 record to use. */ List <SupBook> supBooksExisting = WbStream.GetAllRecordsByType <SupBook>(); List <ExternSheet> externSheetsExisting = WbStream.GetAllRecordsByType <ExternSheet>(); List <Lbl> existingLbls = WbStream.GetAllRecordsByType <Lbl>(); ExternSheet lastExternSheet; if (supBooksExisting.Count > 0 || externSheetsExisting.Count > 0) { lastExternSheet = externSheetsExisting.Last(); } else { InitializeGlobalStreamLabels(); lastExternSheet = WbStream.GetAllRecordsByType <ExternSheet>().Last();; } // For now we assume that any labels being added belong to the last BoundSheet8 we added Lbl newLbl = new Lbl(label, (ushort)(WbStream.GetAllRecordsByType <BoundSheet8>().Count)); if (isUnicode) { newLbl.SetName(new XLUnicodeStringNoCch(label, true)); } if (isMacroStack) { newLbl.fProc = true; newLbl.fFunc = true; } if (isHidden) { newLbl.fHidden = true; } if (rgce != null) { newLbl.SetRgce(rgce); } else { newLbl.cce = 0; } if (existingLbls.Count > 0) { WbStream = WbStream.InsertRecord(newLbl, existingLbls.Last()); } else { WbStream = WbStream.InsertRecord(newLbl, lastExternSheet); } WbStream = WbStream.FixBoundSheetOffsets(); return(WbStream); }