SetText
Replaces the whole text of the current run with the specified text, keeping the run properties.
Syntax
expression.SetText(text);
expression - A variable that represents an ApiRun class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| text | Required | string | number[] | The new text of the run, as a string or as an array of character codes. |
Returns
Example
Replace the whole text of a run in one call in a presentation.
// How do I replace the text of a run without losing its formatting in a presentation?
// Swap the wording of a run on a slide while its formatting stays in place in a presentation.
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("flowChartMagneticTape", 300 * 36000, 130 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
const docContent = shape.GetDocContent();
const paragraph = docContent.GetElement(0);
const run = Api.CreateRun();
run.SetBold(true);
run.SetFontSize(30);
run.AddText("Draft wording.");
paragraph.AddElement(run);
run.SetText("Final wording, still bold.");
slide.AddObject(shape);