Class Tab

Tab 键

Google 文档文档中的标签页。

// Get all of the first-level tabs (tabs that are not nested within a parent tab) in the
// document.
var tabs = DocumentApp.openById('abc123456').getTabs();

// Get a specific tab based on the tab ID.
var tab = DocumentApp.openById('abc123456').getTab('t.0');

方法

方法返回类型简介
asDocumentTab()DocumentTabDocumentTab 的形式检索标签页内容。
getChildTabs()Tab[]检索此标签页中嵌套的子标签页。
getId()String检索标签页的 ID。
getIndex()Integer检索父标签页内标签页的索引(从 0 开始)。
getTitle()String检索标签页的标题。
getType()TabType检索标签页的类型。

详细文档

asDocumentTab()

DocumentTab 的形式检索标签页内容。

返回

DocumentTab - 以 DocumentTab 形式显示的标签页。


getChildTabs()

检索此标签页中嵌套的子标签页。

返回

Tab[] - 此标签页中嵌套的子标签页。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getId()

检索标签页的 ID。

返回

String - 标签页的 ID。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getIndex()

检索父标签页内标签页的索引(从 0 开始)。

返回

Integer - 标签页在父项中的索引。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getTitle()

检索标签页的标题。

返回

String - 标签页的标题。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

检索标签页的类型。

在投放到更多位置之前,请先使用此方法确定此 Tab 的内容类型 特定类型(使用 asDocumentTab())。

var tab = DocumentApp.getActiveDocument().getTab('t.0');
// 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.
}

返回

TabType - 标签页的类型。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents