Skip to main content

Search

Searches for a scope of a table object.

The search results are a collection of ApiRange objects.

Syntax​

expression.Search(sText, isMatchCase);

expression - A variable that represents an ApiTable class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
sTextRequiredstring | RegExpSearch string, or a regular expression to match. When a RegExp is passed, the isMatchCase parameter is ignored (control case sensitivity with the "i" flag instead).
isMatchCaseRequiredbooleanCase sensitive or not.

Returns​

ApiRange[]

Example​

Find text in a table by a string and by a regular expression, then bold the matches.

// Combine a keyword lookup across cells with a RegExp that matches every cell number.

// Bold the first keyword match, then bold each number found by the /\d+/g expression.

let doc = Api.GetDocument();
let tableStyle = doc.CreateStyle("CustomTableStyle", "table");
tableStyle.SetBasedOn(doc.GetStyle("Bordered"));
let table = Api.CreateTable(3, 3);
table.SetWidth("percent", 100);
table.SetStyle(tableStyle);
table.GetCell(0, 0).GetContent().GetElement(0).AddText("Cell 1");
table.GetCell(0, 1).GetContent().GetElement(0).AddText("Cell 2");
table.GetCell(0, 2).GetContent().GetElement(0).AddText("Cell 3");
doc.Push(table);

let byKeyword = table.Search("Cell");
byKeyword[0].SetBold(true);

let byRegExp = table.Search(/\d+/g);
for (let index = 0; index < byRegExp.length; index++)
byRegExp[index].SetBold(true);