如何跳過突出顯示部分並直接格式化它們?下面的代碼搜索單詞「測試」,並加粗它&突出顯示黃色。希望這可以幫助。
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我已澄清我的問題,包括總體目標。正如你可以看到你的(非常好的)答案在這方面沒有幫助。 –