GetTextRange
Returns an ApiTextRange object that represents the part of the text contained in the current run. The run must be attached to the document before calling this method.
Syntax
expression.GetTextRange(start, end);
expression - A variable that represents an ApiRun class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| start | Optional | number | 0 | Start character position (0-based, inclusive) relative to the run. |
| end | Optional | number | End character position (0-based, exclusive). Defaults to the end of the run. |
Returns
ApiTextRange | null
Example
Colour a part of a text run of a shape on a slide through a text range.
// Positions are counted from the beginning of the run, so the rest of the paragraph is untouched.
// Take the range of the first word of the run and paint it red.
const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();
const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("rect", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
slide.AddObject(shape);
const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);
const run = Api.CreateRun();
run.AddText("Hello World");
paragraph.AddElement(run);
const range = run.GetTextRange(0, 5);
range.SetColor(Api.RGB(255, 0, 0));