文件,內含一或多個 Tab 物件,每個物件都包含 RTF 和表格、清單等元素。
您可以使用 Document 開啟或建立文件。
// Open a document by ID. let doc = DocumentApp.openById('<my-id>'); // Create and open a document. doc = DocumentApp.create('Document Title');
Document 類別中直接存取及修改文字內容的方法,會對活動分頁 (在繫結至特定文件的指令碼中) 或第一個分頁 (如果沒有活動分頁) 執行作業。依賴這些方法的指令碼 (例如 get) 可以遷移至支援使用 get,然後使用 Tab.asDocumentTab() 的分頁。
方法
內容詳盡的說明文件
add Bookmark(position)
在第一個分頁中加入指定 Position 的 Bookmark,或在繫結至文件的指令碼中,加入目前的分頁。如要在任何分頁中新增書籤,請使用 Document 方法。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the active or first tab's body and adds a paragraph. const paragraph = doc.getBody().appendParagraph('My new paragraph.'); // Creates a position at the first character of the paragraph text. const position = doc.newPosition(paragraph.getChild(0), 0); // Adds a bookmark at the first character of the paragraph text. const bookmark = doc.addBookmark(position); // Logs the bookmark ID to the console. console.log(bookmark.getId());
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
position | Position | 新書籤的位置。 |
回攻員
Bookmark:新書籤。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
add Editor(emailAddress)
add Editor(user)
add Editors(emailAddresses)
add Header()
如果第一個分頁或 (如果是繫結至文件的指令碼) 目前分頁沒有標頭區段,則新增標頭區段。如要在任何分頁中新增標題區段,請使用 Document 方法。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Adds a header to the document's active or first tab. const header = doc.addHeader(); // Sets the header text to 'This is a header.' header.setText('This is a header');
回攻員
Header:分頁標題。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
add Named Range(name, range)
在第一個分頁中新增 Named,也就是具有名稱和 ID 的 Range,可用於稍後擷取;如果是繫結至文件的指令碼,則會新增至目前的分頁。如要在任何分頁中新增 Named,請使用 Document 方法。名稱不一定會是唯一的;同一份文件中的多個不同範圍可以共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在文件中是唯一的,就像 HTML 中的 ID 一樣。
在文件中新增 Named 後,就無法修改,只能移除。
存取文件的任何指令碼都可以存取 Named。為避免指令碼之間發生非預期的衝突,建議在範圍名稱加上獨一無二的字串前置字元。
// Creates a named range that includes every table in the active tab. const doc = DocumentApp.getActiveDocument(); const rangeBuilder = doc.newRange(); const tables = doc.getBody().getTables(); for (let i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } // Adds the named range to the document's active tab. doc.addNamedRange('Document tables', rangeBuilder.build());
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
name | String | 範圍名稱 (不必是專用的),長度必須介於 1 至 256 個字元之間。 |
range | Range | 要與名稱建立關聯的元素範圍;範圍可以是有效選取範圍、搜尋結果,或使用 new 手動建構。 |
回攻員
Named - Named。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
add Viewer(emailAddress)
add Viewer(user)
add Viewers(emailAddresses)
get Active Tab()
取得文件中目前使用者的有效 Tab。指令碼只能存取執行指令碼的使用者目前開啟的分頁,且指令碼必須繫結至文件。
// Display a dialog box that shows the title of the tab that the // user is currently viewing. const tab = DocumentApp.getActiveDocument().getActiveTab(); DocumentApp.getUi().alert(`ID of selected tab: ${tab.getTitle()}`);
回攻員
Tab:使用者目前使用的 Tab,如果指令碼未繫結至文件,則為 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get As(contentType)
以指定型別的 Blob 形式擷取目前的 Document 內容。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the document as a PDF. const pdf = doc.getAs('application/pdf'); // Logs the name of the PDF to the console. console.log(pdf.getName());
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
content | String | 要轉換的 MIME 類型;支援 'application/pdf' 和 'text/markdown'。 |
回攻員
Blob:目前的文件 (Blob)。
get Blob()
以 Blob 形式擷取目前的 Document 內容。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Retrieves the current document's contents as a blob and logs it to the // console. console.log(doc.getBlob().getContentType());
回攻員
Blob:目前的文件 (Blob)。
get Body()
擷取第一個分頁的 Body,或是繫結至文件的指令碼目前分頁的 Document。如要取得任何分頁的 Document,請使用 Document 方法。
分頁可能包含不同類型的區段 (例如 Header、Footer)。分頁的有效區段為 Body。
Document 中的元素方法會委派給作用中的 Body。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the active or first tab's body. const body = doc.getBody(); // Gets the body text and logs it to the console. console.log(body.getText());
回攻員
Body - 分頁主體部分。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Bookmark(id)
在第一個分頁中取得具有指定 ID 的 Bookmark,或是取得繫結至文件的指令碼目前的分頁。如要在任何分頁中取得書籤,請使用 Document 方法。如果分頁中沒有這類 Bookmark,這個方法會傳回 null。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the bookmark by its ID in the document's active or first tab. const bookmark = doc.getBookmark('id.xyz654321'); // If the bookmark exists, logs the character offset of its position to the // console. otherwise, logs 'No bookmark exists with the given ID.' to the // console. if (bookmark) { console.log(bookmark.getPosition().getOffset()); } else { console.log('No bookmark exists with the given ID.'); }
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
id | String | Bookmark 的 ID。 |
回攻員
Bookmark|null:具有指定 ID 的 Bookmark,或如果分頁中沒有這類 Bookmark,則為 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Bookmarks()
取得第一個分頁中的所有 Bookmark 物件,或取得繫結至文件的指令碼所屬的現用分頁。如要取得任何分頁中的所有書籤,請使用 Document 方法。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. const doc = DocumentApp.openById('123abc'); // Gets all of the bookmarks in the document's active or first tab. const bookmarks = doc.getBookmarks(); // Logs the number of bookmarks in the tab to the console. console.log(bookmarks.length);
回攻員
Bookmark[]:分頁中的 Bookmark 物件陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Cursor()
取得使用者在現用分頁中的游標。指令碼只能存取執行指令碼的使用者游標,且指令碼必須繫結至文件。
// Insert some text at the cursor position and make it bold. const cursor = DocumentApp.getActiveDocument().getCursor(); if (cursor) { // Attempt to insert text at the cursor position. If the insertion returns // null, the cursor's containing element doesn't allow insertions, so show the // user an error message. const element = cursor.insertText('ಠ‿ಠ'); if (element) { element.setBold(true); } else { DocumentApp.getUi().alert('Cannot insert text here.'); } } else { DocumentApp.getUi().alert('Cannot find a cursor.'); }
回攻員
Position|null:代表使用者的游標,如果使用者未在分頁中放置游標,或指令碼未繫結至文件,則為 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Editors()
get Footnotes()
擷取第一個分頁主體中的所有 Footnote 元素,或是擷取與文件繫結的指令碼中,有效分頁的主體。如要取得任何分頁中的所有註腳,請使用 Document 方法。
對 get 的呼叫會導致對分頁元素的疊代。如果是大型分頁,請避免不必要地呼叫這個方法。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the first footnote in the active or first tab's body. const footnote = doc.getFootnotes()[0]; // Logs footnote contents to the console. console.log(footnote.getFootnoteContents().getText());
回攻員
Footnote[]|null:分頁的註腳。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Header()
擷取第一個分頁的標題區段,或擷取繫結至文件的指令碼目前分頁的標題區段。如要取得任何分頁的標題部分,請使用 Document 方法。
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('123abc'); // Gets the text of the active or first tab's header and logs it to the console. console.log(doc.getHeader().getText());
回攻員
Header - 分頁的標題。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Id()
擷取文件的專屬 ID。文件 ID 會與 Document 搭配使用,開啟特定文件執行個體。
回攻員
String:文件的 ID。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Language()
取得文件的語言代碼。這是文件編輯器「檔案」>「語言」中顯示的語言,可能與文件實際內容的語言不同。
回攻員
String:文件語言,或未定義時的 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Name()
擷取文件標題。
回攻員
String:文件標題。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Range By Id(id)
在第一個分頁中取得具有指定 ID 的 Named,或是取得繫結至文件的指令碼目前的分頁。如要在任何分頁中取得具有指定 ID 的 Named,請使用 Document 方法。如果分頁中沒有這類 Named,這個方法會傳回 null。名稱不一定會是唯一的,即使在不同分頁之間也是如此;同一分頁中的多個不同範圍可能會共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在分頁中是唯一的,就像 HTML 中的 ID 一樣。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
id | String | 範圍的 ID,在分頁中不得重複。 |
回攻員
Named - 具有指定 ID 的 Named,如果分頁中沒有這類範圍,則為 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Ranges()
取得第一個分頁中的所有 Named 物件,或取得繫結至文件的指令碼所屬的現用分頁。如要取得任何分頁中的所有 Named 物件,請使用 Document 方法。
任何存取分頁的指令碼都可以存取 Named。為避免指令碼之間發生非預期的衝突,建議您在範圍名稱加上專屬字串前置字元。
回攻員
Named:分頁中的 Named 物件陣列,可能包含多個同名範圍。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Named Ranges(name)
在第一個分頁中取得所有具有指定名稱的 Named 物件,或是取得與文件繫結的指令碼所屬的有效分頁。如要取得任何分頁中的所有 Named 物件,請使用 Document 方法。名稱不一定會是唯一的,即使是跨分頁也一樣;同一個分頁中的多個不同範圍可能會共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在分頁中是專屬的,就像 HTML 中的 ID 一樣。
任何存取文件的指令碼都可以存取 Named。為避免指令碼之間發生非預期的衝突,建議您在範圍名稱加上專屬字串前置字元。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
name | String | 範圍的名稱 (不一定不得重複)。 |
回攻員
Named:具有指定名稱的分頁中的 Named 物件陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Selection()
取得現用分頁中使用者選取的內容。指令碼只能存取執行指令碼的使用者選取的內容,且指令碼必須繫結至文件。
// Display a dialog box that tells the user how many elements are included in // the selection. const selection = DocumentApp.getActiveDocument().getSelection(); if (selection) { const elements = selection.getRangeElements(); DocumentApp.getUi().alert(`Number of selected elements: ${elements.length}`); } else { DocumentApp.getUi().alert('Nothing is selected.'); }
回攻員
Range|null:代表使用者選取的內容,如果使用者未在分頁中選取任何內容、只選取段落結尾、只選取段落結尾和新行,或指令碼未繫結至文件,則為 null。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Supported Language Codes()
取得 Google 文件檔案支援的所有語言代碼。
回攻員
String[]:語言代碼陣列。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Tab(tabId)
get Tabs()
取得文件中所有未巢狀化的 Tab。
分頁可以包含子分頁,也就是巢狀分頁。使用 Tab.getChildTabs() 即可存取子項分頁。
回攻員
Tab[]:文件中所有 Tab 的清單。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Url()
擷取存取目前文件的網址。
const doc = DocumentApp.getActiveDocument(); // Send out the link to open the document. MailApp.sendEmail('<email-address>', doc.getName(), doc.getUrl());
回攻員
String:存取目前文件的網址。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
get Viewers()
new Position(element, offset)
建立新的 Position,這是指分頁中的位置,相對於第一個分頁中的特定元素,或是繫結至文件的指令碼所屬的現用分頁。如要建立與任何分頁中位置相關的 Position,請使用 Document 方法。使用者游標會以 Position 表示,這只是其中一種用途。
// Append a paragraph to the active tab, then place the user's cursor after the // first word of the new paragraph. const doc = DocumentApp.getActiveDocument(); const paragraph = doc.getBody().appendParagraph('My new paragraph.'); const position = doc.newPosition(paragraph.getChild(0), 2); doc.setCursor(position);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
element | Element | 應包含新 Position 的元素;這必須是 Text 元素或容器元素 (例如 Paragraph)。 |
offset | Integer | 如果是 Text 元素,則為 Position 前的半形字元數;如果是其他元素,則為同一容器元素內 Position 前的子元素數。 |
回攻員
Position - 新的 Position。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
new Range()
建立建構工具,用於從第一個分頁中的分頁元素建構 Range 物件,或從繫結至文件的指令碼所屬的現用分頁建構物件。如要建立建構工具,從任何分頁中的分頁元素建構 Document 物件,請使用 Document 方法。
// Change the user's selection to a range that includes every table in the // active tab. const doc = DocumentApp.getActiveDocument(); const rangeBuilder = doc.newRange(); const tables = doc.getBody().getTables(); for (let i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } doc.setSelection(rangeBuilder.build());
回攻員
Range:新的建構工具。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
remove Editor(emailAddress)
從 Document 的編輯者清單中移除指定使用者。如果使用者屬於具有一般存取權的使用者類別,例如 Document 是與使用者的整個網域共用,或是 Document 位於使用者可存取的共用雲端硬碟中,這個方法就無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從檢視者清單中移除該使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
email | String | 要移除的使用者電子郵件地址。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
remove Editor(user)
從 Document 的編輯者清單中移除指定使用者。如果使用者屬於具有一般存取權的使用者類別,例如 Document 是與使用者的整個網域共用,或是 Document 位於使用者可存取的共用雲端硬碟中,這個方法就無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從檢視者清單中移除該使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
user | User | 要移除的使用者代表。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
remove Viewer(emailAddress)
從 Document 的觀眾和留言者清單中移除指定使用者。如果使用者是編輯者,而非檢視者或留言者,這個方法不會有任何作用。如果使用者屬於具有一般存取權的使用者類別 (例如 Document 與使用者的整個網域共用,或 Document 位於使用者可存取的共用雲端硬碟中),這個方法也無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從編輯者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
email | String | 要移除的使用者電子郵件地址。 |
回攻員
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
remove Viewer(user)
從 Document 的觀眾和留言者清單中移除指定使用者。如果使用者是編輯者而非檢視者,這個方法不會生效。如果使用者屬於具有一般存取權的使用者類別 (例如 Document 與使用者的整個網域共用,或 Document 位於使用者可存取的共用雲端硬碟中),這個方法也無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從編輯者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
user | User | 要移除的使用者代表。 |
回攻員
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
save And Close()
儲存目前的 Document。導致待處理的更新遭到清除並套用。
指令碼執行完畢後,系統會自動為每個開啟的可編輯 Document 叫用 save 方法。
已結案的 Document 無法編輯。使用 Document 重新開啟特定文件進行編輯。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Active Tab(tabId)
將目前文件中使用者選取的 Tab 設為具有指定 ID 的分頁。
const doc = DocumentApp.getActiveDocument(); // Sets the user's selected tab by its ID. // TODO(developer): Replace the ID with your own. const tab = doc.setActiveTab('123abc');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
tab | String | 要設為使用中的分頁 ID。 |
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Cursor(position)
設定使用者的游標 (指定 Position)。指令碼只能存取執行指令碼的使用者游標,且指令碼必須繫結至文件。
從非使用中的 Tab 提供 Position,會切換使用者的有效分頁。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); // Append a paragraph, then place the user's cursor after the first word of the // new paragraph. const paragraph = documentTab.getBody().appendParagraph('My new paragraph.'); const position = documentTab.newPosition(paragraph.getChild(0), 2); doc.setCursor(position);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
position | Position | 新的游標位置。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Language(languageCode)
設定文件的語言代碼。這是文件編輯器「檔案」>「語言」中顯示的語言,可能與文件實際內容的語言不同。使用 get 取得所有有效的語言代碼。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
language | String | 語言代碼。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
set Name(name)
set Selection(range)
根據 Range,在有效分頁中設定使用者的選取項目。指令碼只能存取執行指令碼的使用者所選取的內容,且指令碼必須繫結至文件。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); // Change the user's selection to a range that includes every table in the // document. const rangeBuilder = documentTab.newRange(); const tables = documentTab.getBody().getTables(); for (let i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } doc.setSelection(rangeBuilder.build());
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
range | Range | 要選取的新元素範圍。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要一或多個下列範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents