Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Josua Schmid
Josua Schmid

Posted on

     

Auto-colorize Google Docs

Formatting options in Google Docs are limited. And that's good because formatting can be a lot of manual work (e.g. in Microsoft Word). But sometimes it would be nice to have some fine-grained auto-formatting feature like coloring a certain word if it occurs in the text.

Luckily there is Google Apps Script. You can apply some JavaScript code to your documents very easily, like for example to color some words selected with a Regular Expression:

functioncolorText(){vardoc=DocumentApp.getActiveDocument();varbody=doc.getBody();varparagraphs=body.getParagraphs();for(vari=0;i<paragraphs.length;i++){varsearchResult=paragraphs[i].findText('^.*\:');if(searchResult){varstartIndex=searchResult.getStartOffset();varendIndex=searchResult.getEndOffsetInclusive();searchResult.getElement().asText().setForegroundColor(startIndex,endIndex,'#571f4e');}}}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

brewing beer, engineering software – or the other way around
  • Location
    Rapperswil, Switzerland
  • Education
    B.Sc. HSR CS
  • Work
    Engineer at Renuo
  • Joined

More fromJosua Schmid

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp