跳到主要内容

Search

在当前幻灯片版式中搜索指定文本,并将找到的所有匹配项作为文本范围返回。

语法​

expression.Search(text, isMatchCase, isWholeWords);

expression - 表示 ApiLayout 类的变量。

参数​

名称必需/可选数据类型默认值描述
text必需string | RegExp要搜索的文本,或要匹配的正则表达式。传递 RegExp 时,将忽略 isMatchCase 和 isWholeWords(改用 "i" 标志控制是否区分大小写)。
isMatchCase可选booleanfalse是否区分大小写。
isWholeWords可选booleanfalse是否仅搜索全字匹配。

返回值​

ApiTextRange[]

示例​

查找幻灯片版式上某个单词的所有匹配项,并将第一个匹配项设为粗体。

// Search is scoped to this layout, returning each match as a text range.

// Add a shape to the layout, search it for a keyword, and embolden the first result.

const presentation = Api.GetPresentation();
const master = presentation.GetMaster(0);
const layout = master.GetLayout(0);

const shape = Api.CreateShape("rect", 300 * 36000, 100 * 36000);
shape.SetPosition(608400, 1267200);
layout.AddObject(shape);
shape.GetTextRange().SetText("Preliminary layout draft and preliminary review.");

const results = layout.Search("preliminary");
results[0].SetBold(true);