Skip to main content

Range

A live span of one paragraph’s text, in UTF-16 offsets local to it. The paragraph anchor is an element reference (structural edits cannot rot it); the offsets are validated against a text snapshot before every edit. When other edits shift the span, the range follows its snapshot text if it still occurs exactly once in the paragraph — so a forward search-and-replace loop works — and throws on any ambiguity instead of landing on the wrong span. Import from @reductoai/docx/node, @reductoai/docx/officejs.

Range properties

Range.clear()

Range.compareLocationWith()

office.js Range.compareLocationWith: where this range sits relative to another in document order. Ranges of two stories read Unrelated.

Range.convertToTable()

Extension (VBA Range.ConvertToTable): each paragraph of the range becomes a row, split into cells at the separator (Tabs by default). The range’s handle is spent; use the returned Table.

Range.delete()

Remove the range; one that holds a paragraph mark takes the mark (and so the paragraph) too.

Range.expandTo()

office.js Range.expandTo: the span from the earlier start to the later end of two ranges in document order. Both must live in the SAME story.

Range.expandToOrNullObject()

expandTo, with the null object instead of the cross-story/detached refusals.

Range.getBookmarks()

Names of the bookmarks covering this range, in document order.

Range.getComments()

Range.getContentControls()

Range.getHtml()

As Word: tables as <table>, <h1>-<h6> for headings, list markers as text, b/i/u/s/sup/sub and links inline. A paragraph whose mark is outside the range is written inline.
The address of the hyperlink containing this range, if any: the target URL for an external link (r:id), "#Bookmark" for an internal one (w:anchor). (OfficeJS range.hyperlink is one read/write property; explicit verbs keep “link this text” apart from “replace this text”.)

Range.getHyperlinkRanges()

office.js Range.getHyperlinkRanges: the hyperlink child ranges inside this range.

Range.getHyperlinkTooltip()

The ScreenTip (w:tooltip) of the hyperlink containing this range: the read half of setHyperlink’s second argument, undefined when the range is unlinked or the link carries none. OfficeJS has no tooltip member at all.

Range.getNextTextRange()

office.js Range.getNextTextRange: the next segment of the story, or ItemNotFound.

Range.getNextTextRangeOrNullObject()

getNextTextRange, with the null object instead of every refusal it makes.

Range.getOoxml()

The range’s own WML, a text-only HTML span, and the reviewed-text projection.

Range.getRange()

Range.getReviewedText()

Range.getTextRanges()

Range.getTrackedChanges()

Range.highlight()

Range.insertBookmark()

Bookmark this range; re-using a name moves that bookmark here, as Word does.

Range.insertBreak()

Insert a break before or after this range’s start/end paragraph.

Range.insertCanvas()

Insert an empty floating canvas anchored to this range’s paragraph; geometry in points.

Range.insertCaption()

VBA Range.InsertCaption: a Caption paragraph numbered by SEQ label, below (default) or above the body block that holds this range; later captions of the label renumber.

Range.insertComment()

A spanning range opens the comment in its first paragraph and closes it in its last, as Word does.

Range.insertContentControl()

Wrap this range in a content control: a block-level w:sdt around the blocks of a paragraph-aligned range (one paragraph or many), an inline w:sdt around the runs of a partial one-paragraph range.

Range.insertCrossReference()

VBA Range.InsertCrossReference: a REF, PAGEREF or NOTEREF field to the referenceItemth entry of Document.getCrossReferenceItems(referenceType), or the entry with that text. A heading, numbered item, note or caption gets Word’s hidden _Ref bookmark, reused when one is there.

Range.insertEndnote()

Insert an endnote mark at this range’s end; the note body starts with insertText.

Range.insertField()

Author a field at one of Word’s five anchor points; text carries its switches.

Range.insertFileFromBase64()

A .docx’s body at insertOoxml’s anchors, with its parts; async, the file is unpacked here.

Range.insertFootnote()

Insert a footnote mark at this range’s end; the note body starts with insertText.

Range.insertGeometricShape()

Insert a floating preset shape anchored to this range’s paragraph; geometry in points.

Range.insertHtml()

The named HTML subset at those same anchors; any other tag throws by name.

Range.insertInlinePictureFromBase64()

Insert a PNG, JPEG, GIF, BMP, TIFF, EMF or WMF at its natural size, anchored to one of the range’s five edges.

Range.insertMath()

Extension: TeX math as a native Office Math equation, at insertOoxml’s anchors.

Range.insertOoxml()

A WML fragment or pkg:package payload at any of the range’s five anchors.

Range.insertParagraph()

Range.insertScene()

Insert one floating group of preset shapes and connectors anchored to this range’s paragraph.

Range.insertSymbol()

Extension: VBA’s Range.InsertSymbol; a U+F000–U+F0FF code is a w:sym, any other text in font.

Range.insertTable()

Insert a table before or after this range’s start/end paragraph.

Range.insertText()

The inserted text’s range (first line); a newline splits only where no text crosses the split.

Range.insertTextBox()

Insert a floating textbox anchored to this range’s paragraph; geometry in points.

Range.intersectWith()

office.js Range.intersectWith: the span the two ranges share, same story only.

Range.intersectWithOrNullObject()

intersectWith, with the null object instead of every refusal it makes.

Range.removeHighlight()

Literal hits of needle inside this range.

Range.set()

Link this range’s text; see setRangeHyperlink for the whole contract.

Range.sort()

Extension (VBA Range.Sort on text): the range’s paragraphs reorder by their text, ties stable. excludeHeader keeps the first paragraph in place. Sort a table with Table.sort.

Range.split()

office.js Range.split: getTextRanges over delimiters, with the two extra knobs. Not implemented. These Office.js members throw: characterWidth, combineCharacters, conflicts, disableCharacterSpaceGrid, editors, fitTextWidth, grammarChecked, highlightColorIndex, horizontalInVertical, id, isEndOfRowMark, isTextVisibleOnScreen, kana, languageDetected, languageIdOther, pages, showAll, spellingChecked, twoLinesInOne, detectLanguage, insertPictureFromBase64, select.

RangeCollection

OfficeJS-flavored live collection: items is recomputed on every access. Import from @reductoai/docx/node, @reductoai/docx/officejs.

RangeCollection properties

RangeCollection.at()

RangeCollection.getFirst()

RangeCollection.getFirstOrNullObject()

OfficeJS null-object variant; inspect isNullObject before other members.

RangeCollection.getItem()

OfficeJS spelling of at().

RangeCollection.getLast()

RangeCollection.getLastOrNullObject()

OfficeJS null-object variant; inspect isNullObject before other members.

SearchOptions

OfficeJS SearchOptions shape. Literal search supports case, whole-word, prefix/suffix matching; matchWildcards switches to Word’s wildcard syntax (case-sensitive, the other switches ignored as Word greys them out); ignorePunct/ignoreSpace let the text hold punctuation/spaces the needle lacks. Import from @reductoai/docx/node, @reductoai/docx/officejs.