Skip to main content

SetHighlight

Specifies a highlighting color which is applied as a background to the contents of the current Range.

Syntax

expression.SetHighlight(sColor);

expression - A variable that represents a ApiRange class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sColorRequiredhighlightColorAvailable highlight color.

Returns

ApiRange | null

Example

Add a background highlight color behind a range of text in a document.

// How do I highlight a portion of text with a colored background in a document?

// Draw attention to specific words by painting a color behind them in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("ONLYOFFICE Document Builder");
let range = doc.GetRange(0, 26);
range.SetHighlight("lightGray");