Skip to content

Instantly share code, notes, and snippets.

@aplater
Forked from tanaikech/submit.md
Created May 4, 2021 22:08
Show Gist options
  • Save aplater/db9a950cb11586e601e25af624361433 to your computer and use it in GitHub Desktop.
Save aplater/db9a950cb11586e601e25af624361433 to your computer and use it in GitHub Desktop.
Changing Font of Selected Text to 'Google Sans' on Google Document using Google Apps Script

Changing Font of Selected Text to 'Google Sans' on Google Document using Google Apps Script

This is a sample script for changing the font of selected text to Google Sans on Google Document using Google Apps Script.

Sample script

Please copy and paste the following script to the script editor of Google Document And, when you use this script, please select a text in Google Document and run the script. By this, the font of selected text is changed to Google Sans.

function myFunction() {
  const selection = DocumentApp.getActiveDocument().getSelection();
  const element = selection.getRangeElements()[0];
  element
    .getElement()
    .asText()
    .setFontFamily(
      element.getStartOffset(),
      element.getEndOffsetInclusive(),
      "Google Sans"
    );
}

References

This sample script was posted for explaining at https://groups.google.com/g/google-apps-script-community/c/ehC7C95W5t0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment