1
votes

I have a Google Document with paragraphs formatted as Heading 1 and Heading 2. I would like to create a table of content (TOC) in the document by script, not manually.

I have tried to find a tutorial or something like that, but I cannot. Maybe because this is not possible? Do I have to make the TOC by using the menu in Docs?

All I could find is: Class TableOfContents

Please let me know if a scripted TOC is possible.

1

1 Answers

1
votes

Some elements in Google Docs, including TableOfContents, can't be inserted programmatically. From GAS documentation:

Elements shown in bold can be inserted; non-bold elements can only be manipulated in place.

More details here https://developers.google.com/apps-script/guides/docs