WordRange
OfficeIMO.Word
A span of visible text in one story of a Word document: the body, a table, a header or footer, a footnote or an endnote. A range can start and end inside runs and can cross runs and paragraphs.
Inheritance
- object
- WordRange
Remarks
Get a range from , or . Offsets count the paragraph's visible text: deleted text and field instructions are not counted, a tab is one character and a line break is \n. Replacing text through a range moves the other ranges of the same document that follow it, so you can replace every search hit in document order. A range whose text was replaced by another range, or edited outside the range API, throws when used. Edits that cannot be made safely throw and leave the text unchanged: replacing or linking field results, tracked insertions or deletions, equations, drawings, footnote references or part of a content control, and joining paragraphs across a table or a section break.
Usage
Explore 7 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 6
- Method WordBookmark.GetRange
- Method WordParagraph.GetRange
- Method WordRange.ExtendTo
- Method WordRange.Format
- Method WordRange.Replace
- Property WordSearchResult.Ranges
Accepted by parameters 1
- Method WordRange.ExtendTo
Methods
public WordBookmark AddBookmark(string name) #Adds a bookmark that spans the range.
Parameters
- name string
- Bookmark name.
public WordComment AddComment(string author, string initials, string text) #Adds a comment on the range.
Parameters
- author string
- Comment author.
- initials string
- Author initials.
- text string
- Comment text.
public WordComment AddComment(string author, string initials, Action<WordParagraph> content) #Adds a comment on the range with a formatted body.
Parameters
- author string
- Comment author.
- initials string
- Author initials.
- content System.Action<OfficeIMO.Word.WordParagraph>
- Writes the comment body into its first paragraph, for example p => p.AddText("Check ").AddText("this").SetBold().
public WordHyperLink AddHyperLink(Uri uri) #Turns the range text into a hyperlink to an external address. The text keeps its formatting and gets the Hyperlink character style.
Parameters
- uri System.Uri
- Link target.
public WordHyperLink AddHyperLink(string anchor) #Turns the range text into a link to a bookmark in the document. The text keeps its formatting and gets the Hyperlink character style.
Parameters
- anchor string
- Name of the target bookmark.
public WordRange ExtendTo(WordRange end) #Returns a range from the start of this range to the end of end, such as a span across several paragraphs.
Parameters
- end OfficeIMO.Word.WordRange
- A range in the same story that does not start before this range.
public WordRange Format(Action<WordParagraph> format) #Formats every run of the range. Runs are split at the range edges first, so text outside the range keeps its formatting.
Parameters
- format System.Action<OfficeIMO.Word.WordParagraph>
- Formats one run, for example r => r.SetBold().SetHighlight(...).
public WordRange Replace(string text) #Replaces the text of the range. The new text takes the formatting of the first replaced character, or of the character before an empty range. \t becomes a tab and \n a line break.
Parameters
- text string
- Replacement text. An empty string deletes the range text.
public WordRange Replace(Action<WordParagraph> content) #Replaces the text of the range with content added through a paragraph: formatted text, hyperlinks, images or fields.
Parameters
- content System.Action<OfficeIMO.Word.WordParagraph>
- Adds the replacement content, for example p => p.AddText("Total").SetBold(). Only inline content is used; paragraph formatting set on p is ignored.
Inherited Methods
Properties
public string Text { get; } #Gets the visible text of the range. Paragraph breaks inside the range are returned as \n.