如何跳过突出显示部分并直接格式化它们?下面的代码搜索单词“测试”,并加粗它&突出显示黄色。希望这可以帮助。
function bold() {
var body = DocumentApp.getActiveDocument().getBody();
var foundElement = body.findText("Testing");
while (foundElement != null) {
// Get the text object from the element
var foundText = foundElement.getElement().asText();
// Where in the element is the found text?
var start = foundElement.getStartOffset();
var end = foundElement.getEndOffsetInclusive();
// Set Bold
foundText.setBold(start, end, true);
// Change the background color to yellow
foundText.setBackgroundColor(start, end, "#FCFC00");
// Find the next match
foundElement = body.findText("Testing", foundElement);
}
}
@OblonMedulla我已澄清我的问题,包括总体目标。正如你可以看到你的(非常好的)答案在这方面没有帮助。 –