Skip to main content

GetText

Returns a text from the specified range.

Syntax

expression.GetText(options);

expression - A variable that represents a ApiRange class.

Parameters

NameRequired/OptionalData typeDefaultDescription
optionsOptionalobjectOptions for formatting the returned text.
options.NumberingOptionalbooleantrueDefines if the resulting string will include numbering or not.
options.MathOptionalbooleantrueDefines if the resulting string will include mathematical expressions or not.
options.NewLineSeparatorOptionalstring'\r'Defines how the line separator will be specified in the resulting string. Any symbol can be used. The default separator is "\r".
options.TableCellSeparatorOptionalstring'\t'Defines how the table cell separator will be specified in the resulting string. Any symbol can be used. The default separator is "\t".
options.TableRowSeparatorOptionalstring'\r\n'Defines how the table row separator will be specified in the resulting string. Any symbol can be used. The default separator is "\r\n".
options.ParaSeparatorOptionalstring'\r\n'Defines how the paragraph separator will be specified in the resulting string. Any symbol can be used. The default separator is "\r\n".
options.TabSymbolOptionalstring'\t'Defines how the tab will be specified in the resulting string (does not apply to numbering). Any symbol can be used. The default symbol is "\t".

Returns

string

Example

Read the plain text content from a selected region of text in a document.

// How do I extract the actual words from a highlighted portion of content in a document?

// Pull out the written content of a bounded selection for display or further use in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("\tONLYOFFICE Document Builder");
let range = doc.GetRange(0, 24);
let text = range.GetText({"Numbering": true, "Math": true, "NewLineSeparator": "\r", "TabSymbol": "\t", "NewLineParagraph": true, "TableCellSeparator": "\t", "TableRowSeparator": "\r\n", "ParaSeparator": "\r\n"});
paragraph = Api.CreateParagraph();
paragraph.AddText("The text of the specified range: " + text);
doc.Push(paragraph);