Class Tab Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The Tab class represents a tab within a Google Docs document.
You can retrieve a specific tab by its ID or get all first-level tabs in a document.
The
asDocumentTab()method retrieves the tab contents as a DocumentTab.The
getChildTabs()method retrieves nested child tabs.Methods like
getId(),getIndex(),getTitle(), andgetType()provide information about the tab.
A tab within a Google Docs document.
// Get all of the first-level tabs (tabs that are not nested within a parent// tab) in the document.// TODO(developer): Replace the ID with your own.consttabs=DocumentApp.openById('123abc').getTabs();// Get a specific tab based on the tab ID.// TODO(developer): Replace the IDs with your own.consttab=DocumentApp.openById('123abc').getTab('123abc');
Methods
| Method | Return type | Brief description |
|---|---|---|
as | Document | Retrieves the tab contents as aDocument. |
get | Tab[] | Retrieves the child tabs nested within this tab. |
get | String | Retrieves the ID of the tab. |
get | Integer | Retrieves the 0-based index of the tab within the parent. |
get | String | Retrieves the title of the tab. |
get | Tab | Retrieves the type of tab. |
Detailed documentation
asDocumentTab()
getChildTabs()
getId()
Retrieves the ID of the tab.
Return
String — The ID of the tab.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
getIndex()
Retrieves the 0-based index of the tab within the parent.
Return
Integer — The index of the tab within the parent.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
getTitle()
Retrieves the title of the tab.
Return
String — The title of the tab.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
getType()
Retrieves the type of tab.
Use this method to determine the content type of thisTab before casting to the morespecific type usingas.
consttab=DocumentApp.getActiveDocument().getActiveTab();// Use getType() to determine the tab's type before casting.if(tab.getType()===DocumentApp.TabType.DOCUMENT_TAB){// It's a document tab, write some text to it.tab.asDocumentTab().setText('Hello World!');}else{// There are currently no types other than DOCUMENT_TAB.}
Return
Tab — The tab's type.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.