Can I color certain words in Google Document using Google Apps Script?

后端 未结 4 2311
余生分开走
余生分开走 2020-11-30 03:44

I\'m trying to highlight certain words in my Google Document. I know I can replace text using document.replace, but it only replaces string itself, not formatting. Is there

4条回答
  •  爱一瞬间的悲伤
    2020-11-30 04:03

    I think it's possible with the method setBackgroundColor of class Text in DocumentApp : https://developers.google.com/apps-script/class_text#setBackgroundColor

    You'll have to retrieve your words as Text elements. In order to do that you can use the find method of your object Document, then to iterate over the search results and use getElement. Finally, to convert your Element object into a Text object, you can use asText().

    Hope it'll work ! ;)

提交回复
热议问题