2017-03-21 78 views
2

应用程序脚本是否可以突出显示(如在select中)文本?我想从菜单中运行脚本,然后选择一些文本的所有匹配实例,以便一次性格式化它们。在Google文档中使用谷歌应用程序脚本选择文本

具体来说,我想写一个脚本来突出显示Google Doc中的所有脚注,以便它们可以同时格式化。我是Footnote Stylist附加文档的创建者,它允许用户设计脚注。但我想包括使用任何格式的选项,而不必在自己的添加中包含每个可用的格式选项。

回答

0

如何跳过突出显示部分并直接格式化它们?下面的代码搜索单词“测试”,并加粗它&突出显示黄色。希望这可以帮助。

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); 
 
    } 
 
}

+1

@OblonMedulla我已澄清我的问题,包括总体目标。正如你可以看到你的(非常好的)答案在这方面没有帮助。 –

相关问题