跳到主要内容

在文档中查找指定内容

代码示例

示例 1:搜索并高亮文本

async function example1() {
const success = await app.ActiveDocument.Content.Find.execute('zOffice');
console.log('success:', success);
}

示例 2:全文查找内容 "zOffice" 的数量,全词匹配

async function example2() {
const count = await app.ActiveDocument.Content.Find.findData(
"zOffice",
false,
true
);
}

示例 3:在当前选区内查找内容 "zOffice" 的数量,全词匹配

async function example3() {
const range = await app.ActiveDocument.getSelection();
const count = await range.Find.findData("zOffice", false, true);
}

示例 4:在指定书签内查找内容 "zOffice" 的数量,全词匹配

async function example4() {
const bm = await app.ActiveDocument.Bookmarks.item('bm1');
const range = await bm.range;
const count = await range.Find.findData("zOffice", false, true);
}