2017-03-21 77 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我已澄清我的問題,包括總體目標。正如你可以看到你的(非常好的)答案在這方面沒有幫助。 –

相關問題