小编use*_*207的帖子

查找文本(多次)和突出显示

我想在Google文档中找到一个单词的所有实例并突出显示它们(或评论 - 任何事情都如此突出).我创建了以下函数,但它只找到了单词的第一个外观(在本例中为"the").任何关于如何找到该单词的所有实例的想法将不胜感激!

function findWordsAndHighlight() {
var doc = DocumentApp.openById(Id);
var text = doc.editAsText();
//find word "the"
var result = text.findText("the");
//change background color to yellow
result.getElement().asText().setBackgroundColor(result.getStartOffset(),                result.getEndOffsetInclusive(), "#FFFF00");
};
Run Code Online (Sandbox Code Playgroud)

google-apps-script

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

google-apps-script ×1