Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

WordRange

OfficeIMO.Word

Namespace
OfficeIMO.Word
Assembly
OfficeIMO.Word
Source revision
0eef6a5756b9 with working tree changes
Modifiers
sealed

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.

Accepted by parameters 1

Methods

public WordBookmark AddBookmark(string name) #

Adds a bookmark that spans the range.

Parameters

name string required
Bookmark name.

Returns

WordBookmark The created bookmark.
AddComment 2 overloads
public WordComment AddComment(string author, string initials, string text) #

Adds a comment on the range.

Parameters

author string required
Comment author.
initials string required
Author initials.
text string required
Comment text.

Returns

WordComment The created comment.
public WordComment AddComment(string author, string initials, Action<WordParagraph> content) #

Adds a comment on the range with a formatted body.

Parameters

author string required
Comment author.
initials string required
Author initials.
content System.Action<OfficeIMO.Word.WordParagraph> required
Writes the comment body into its first paragraph, for example p => p.AddText("Check ").AddText("this").SetBold().

Returns

WordComment The created comment.
AddHyperLink 2 overloads
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 required
A range in the same story that does not start before this range.

Returns

WordRange The combined 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> required
Formats one run, for example r => r.SetBold().SetHighlight(...).

Returns

WordRange This range.
Replace 2 overloads
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 required
Replacement text. An empty string deletes the range text.

Returns

WordRange This range, now covering the new 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> required
Adds the replacement content, for example p => p.AddText("Total").SetBold(). Only inline content is used; paragraph formatting set on p is ignored.

Returns

WordRange This range, now covering the new content.

Properties

public string Text { get; } #

Gets the visible text of the range. Paragraph breaks inside the range are returned as \n.