Apps Script: get Paragraph Formatting

As you may have noticed, the Apps Script paragraph.getAttributes() function returns mostly nulls.

This is because paragraph styles are inherited from the named styles unless they’re explicitly set on the paragraph (as demonstrated in this Advanced Docs sample), over-riding the default styles. Unfortunately, the Apps Script Document Service doesn’t provide an API to get the named styles.

Fortunately, the Advanced Docs Service does. The following snippet demonstrates its use; one thing to be aware of is that opening a large document with the Advanced Docs Service can be slow (eg. 30+ seconds for a 150 page document).

When building your own Advanced Docs Service scripts, this rather hard-to-read discovery document is a helpful tool for navigating the available methods. An astonishing amount of supplemental context is available in the Overview.



These are my personal writings; the views expressed in these pages are mine alone and not those of my employer, Google.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store