public virtual void ReplaceTextWithObject(string searchValue, DocumentElement objectToAdd, bool trackChanges = false, RegexOptions options = RegexOptions.None, Formatting matchFormatting = null, MatchFormattingOptions fo = MatchFormattingOptions.SubsetMatch, bool escapeRegEx = true, bool removeEmptyParagraph = true) { if (string.IsNullOrEmpty(searchValue)) { throw new ArgumentException("searchValue cannot be null or empty.", "searchValue"); } if (objectToAdd == null) { throw new ArgumentException("objectToAdd cannot be null.", "objectToAdd"); } // ReplaceText in the container foreach (Paragraph p in this.Paragraphs) { p.ReplaceTextWithObject(searchValue, objectToAdd, trackChanges, options, matchFormatting, fo, escapeRegEx, removeEmptyParagraph); } }
public virtual void ReplaceTextWithObject(string searchValue, DocumentElement objectToAdd, bool trackChanges = false, RegexOptions options = RegexOptions.None, Formatting matchFormatting = null, MatchFormattingOptions fo = MatchFormattingOptions.SubsetMatch, bool escapeRegEx = true, bool removeEmptyParagraph = true) { if (string.IsNullOrEmpty(searchValue)) { throw new ArgumentException("searchValue cannot be null or empty.", "searchValue"); } if (objectToAdd == null) { throw new ArgumentException("objectToAdd cannot be null.", "objectToAdd"); } // ReplaceText in Headers of the document. foreach (var section in this.Document.Sections) { var headerList = new List <Header>() { section.Headers.First, section.Headers.Even, section.Headers.Odd }; foreach (var h in headerList) { if (h != null) { foreach (var p in h.Paragraphs) { p.ReplaceTextWithObject(searchValue, objectToAdd, trackChanges, options, matchFormatting, fo, escapeRegEx, removeEmptyParagraph); } } } } // ReplaceText int main body of document. foreach (Paragraph p in this.Paragraphs) { p.ReplaceTextWithObject(searchValue, objectToAdd, trackChanges, options, matchFormatting, fo, escapeRegEx, removeEmptyParagraph); } // ReplaceText in Footers of the document. foreach (var section in this.Document.Sections) { var footerList = new List <Footer> { section.Footers.First, section.Footers.Even, section.Footers.Odd }; foreach (var f in footerList) { if (f != null) { foreach (var p in f.Paragraphs) { p.ReplaceTextWithObject(searchValue, objectToAdd, trackChanges, options, matchFormatting, fo, escapeRegEx, removeEmptyParagraph); } } } } }