I'd love to be able to collapse and expand sections in my Google Docs document, making large documents easier to navigate. I was wondering if this is possible with Google Apps Script, or if I'd be wasting my time trying to find a way.
-
Could you just use a table of contents? – AshClarke Jun 13 '14 at 01:09
-
7I could (and for now I am). But that leaves me with two versions: One totally expanded (the content) and one collapsed to a certain degree (the table of contents). Nothing in between. No interactivity. That's not the usability I'm aiming for. – Squis Jun 13 '14 at 04:32
-
2Almost 7 years later, is there now anything available OOTB or in Google Apps Script making Collapsible Sections rather efficiently/safely? – flo5783 Apr 26 '21 at 14:47
-
1Man, this would be such a nice feature. – DJG Aug 14 '21 at 12:36
3 Answers
You cannot do anything special in Apps Script, just automate stuff that you can do manually.
So, there's no way to do real collapsing, since there's no such feature in Google Docs. But you can use available functionality in unorthodox ways and make it work for you. For example, you could save the content somewhere else (maybe another document), so you can remove and add "sections" making it look like collapsing. This would have the downside of polluting the document revision history a lot, since every collapse event will be treated as changes to the document. Or you could export the document as HTML, maybe host it on Drive itself and implement the collapsing there, using javascript, then just serve the link to the user.
Anyway, this is just a couple of ideas that recklessly throwing here, which may or may not work for you. But none of will ever be real collapsing on a Google Doc.

- 17,406
- 3
- 56
- 65
As an alternative, we used the outline feature, so we can jump up and down a document quickly:
First open the Outline tool from the menu: View -> Show document outline
If you want to reach a part of your document easily, select some text at that point and give it a heading: Hit the part of the toolbar that says "Normal Text" and change it to "Heading 5".
Remove any headings that you don't want from the Outline by hitting the X next to them.

- 29,306
- 13
- 121
- 110
-
1I see this option `Document outline` in View -> Show Document Outline not in the Tools Menu. May be the location in the menu is changed with the time – Arsal May 13 '20 at 01:41
Another "clue" that might be useable would be to actually "hide" or more precisely make almost invisible some parts of your document using something like the trick described in this other post. The difficult thing will be to find the limits of the parts you would want to hide.... but it's worth giving it a try ;)

- 1
- 1

- 45,904
- 7
- 105
- 131