4
votes

I am using the Google Docs API to update content in a document.

The document has a table of contents, but this doesn't update automatically after making changes in the document using the API.

The only method I've found, is to manually open the document and click the refresh icon next to the table of contents, which will update the TOC.

Is there a way to do this programatically, using the Google Docs API?

1
Using the apps script. Check Class TableOfContents for the properties. And usually, what you are needing for an auto update is a simple trigger, it responds to docs onOpen event. - MαπμQμαπkγVπ.0

1 Answers

5
votes

The Google Docs API does not make available a method that will allow you to automatically refresh the table of contents in a page programmatically. On top of this, without a TableOfContents already in a document, it is currently not possible to obtain links to heading paragraphs, as detailed on Google’s Issue Tracker. This means that elements can not be fetched to insert without manually pressing the refresh button in the document itself.

A feature request to generate and update a Table of Contents programmatically has been submitted here, which you can indicate is a problem you’re also experiencing and get updates by giving it a star.