แท็บภายในเอกสาร Google เอกสาร
// 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. const tabs = DocumentApp.openById('123abc').getTabs(); // Get a specific tab based on the tab ID. // TODO(developer): Replace the IDs with your own. const tab = DocumentApp.openById('123abc').getTab('123abc');
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
as | Document | ดึงข้อมูลเนื้อหาของแท็บเป็น Document |
get | Tab[] | ดึงข้อมูลแท็บย่อยที่ซ้อนอยู่ภายในแท็บนี้ |
get | String | ดึงข้อมูลรหัสของแท็บ |
get | Integer | ดึงข้อมูลดัชนีของแท็บภายในองค์ประกอบหลักโดยอิงตาม 0 |
get | String | ดึงข้อมูลชื่อของแท็บ |
get | Tab | ดึงข้อมูลประเภทของแท็บ |
เอกสารโดยละเอียด
asDocumentTab()
getChildTabs()
getId()
ดึงข้อมูลรหัสของแท็บ
รีเทิร์น
String - รหัสของแท็บ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getIndex()
ดึงข้อมูลดัชนีของแท็บภายในองค์ประกอบหลักโดยอิงตาม 0
รีเทิร์น
Integer - ดัชนีของแท็บภายในแท็บหลัก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getTitle()
ดึงข้อมูลชื่อของแท็บ
รีเทิร์น
String — ชื่อแท็บ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getType()
ดึงข้อมูลประเภทของแท็บ
ใช้วิธีนี้เพื่อกำหนดประเภทเนื้อหาของ Tab นี้ก่อนที่จะแคสต์ไปยังประเภทที่เฉพาะเจาะจงมากขึ้นโดยใช้ asDocumentTab()
const tab = 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. }
รีเทิร์น
TabType — ประเภทของแท็บ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents