Skip to main content

GetRange

Returns a Range object that represents the part of the document contained in the specified run. The run must be attached to the document before calling this method.

Syntax

expression.GetRange(Start, End);

expression - A variable that represents a ApiRun class.

Parameters

NameRequired/OptionalData typeDefaultDescription
StartRequiredNumberStart position index in the current element.
EndRequiredNumberEnd position index in the current element.

Returns

ApiRange

Example

Select a portion of a text run by character positions in a document.

// How do I pick out a specific slice of text within a run in a document?

// Target a character range inside a text run for formatting in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let run = Api.CreateRun();
run.AddText("This is just a sample text.");
paragraph.AddElement(run);
let range = run.GetRange(0, 3);
range.SetBold(true);