Set Google Docs Page Color with script

107 views
Skip to first unread message

Andrew

unread,
Apr 21, 2020, 11:21:25 AM4/21/20
to Google Apps Script Community
Hi all,

In Google Docs, is there a way yo change the Page Color for a Doc using Apps Script? It can be set through the File Menu (File->Page Setup), but I want to change it dynamically through a custom menu/Apps Script.

Thanks.

Tanaike

unread,
Apr 21, 2020, 8:00:36 PM4/21/20
to Google Apps Script Community
  • You want to change the background color using Google Apps Script.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers. In this answer, "getAttributes()" in Class Body is used.

Sample script
const doc = DocumentApp.openById("###");  // Please set the Document ID.

const attributes = {[DocumentApp.Attribute.BACKGROUND_COLOR]: "#FF0000"};
doc
.getBody().setAttributes(attributes);

  • In this script, the background color of body is changed to red.
  • Please enable V8.

Reference


Reply all
Reply to author
Forward
0 new messages