文件,內含一或多個 Tab 物件,每個物件都包含 RTF 格式和表格/清單等元素。
您可以使用 DocumentApp 開啟或建立文件。
// Open a document by ID. let doc = DocumentApp.openById('<my-id>'); // Create and open a document. doc = DocumentApp.create('Document Title');
Document 類別中直接存取及修改文字內容的方法,會對活動分頁 (在繫結至特定文件的指令碼中) 或第一個分頁 (如果沒有活動分頁) 執行作業。依賴這些方法的指令碼 (例如 getBody()) 可以遷移至支援使用 getTabs(),然後使用 Tab.asDocumentTab() 的分頁。
方法
內容詳盡的說明文件
addBookmark(position)
在第一個分頁或 (如果是繫結至文件的指令碼) 目前的分頁中,加入指定 Position 的 Bookmark。如要在任何分頁中新增書籤,請使用 DocumentTab.addBookmark(position) 方法。
// 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
addEditor(emailAddress)
addEditor(user)
addEditors(emailAddresses)
addHeader()
如果第一個分頁或 (如果是繫結至文件的指令碼) 目前分頁沒有標頭區段,則新增標頭區段。如要在任何分頁中新增標題區段,請使用 DocumentTab.addHeader() 方法。
// 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');
回攻員
HeaderSection:分頁標題。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
addNamedRange(name, range)
在第一個分頁中新增 NamedRange,也就是具有名稱和 ID 的 Range,可用於稍後擷取;如果是繫結至文件的指令碼,則會新增至目前的分頁。如要在任何分頁中新增 NamedRange,請使用 DocumentTab.addNamedRange(name, range) 方法。名稱不一定會是唯一的;同一份文件中的多個不同範圍可以共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在文件中是唯一的,就像 HTML 中的 ID 一樣。
在文件中新增 NamedRange 後,就無法修改,只能移除。
存取文件的任何指令碼都可以存取 NamedRange。為避免指令碼之間發生非預期的衝突,建議在範圍名稱加上獨一無二的字串前置字元。
// 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 手動建構。 |
回攻員
NamedRange - NamedRange。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
addViewer(emailAddress)
addViewer(user)
addViewers(emailAddresses)
getActiveTab()
取得文件中目前使用者的有效 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|null:使用者目前使用的 Tab,如果指令碼未繫結至文件,則為 null。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getAs(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)。
getBlob()
以 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)。
getBody()
擷取第一個分頁的 Body,或是繫結至文件的指令碼目前分頁的 DocumentBodySection。如要取得任何分頁的 DocumentBodySection,請使用 DocumentTab.getBody() 方法。
分頁可能包含不同類型的區段 (例如 HeaderSection、FooterSection)。分頁的有效區段為 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
getBookmark(id)
在第一個分頁中取得具有指定 ID 的 Bookmark,或是取得繫結至文件的指令碼目前的分頁。如要在任何分頁中取得書籤,請使用 DocumentTab.getBookmark(id) 方法。如果分頁中沒有這類 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
getBookmarks()
取得第一個分頁中的所有 Bookmark 物件,或取得繫結至文件的指令碼目前的分頁。如要取得任何分頁中的所有書籤,請使用 DocumentTab.getBookmarks() 方法。
// 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
getCursor()
取得使用者在現用分頁中的游標。指令碼只能存取執行指令碼的使用者游標,且指令碼必須繫結至文件。
// 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
getEditors()
getFootnotes()
擷取第一個分頁主體中的所有 Footnote 元素,或擷取與文件繫結的指令碼中,作用中分頁的主體。如要取得任何分頁中的所有註腳,請使用 DocumentTab.getFootnotes() 方法。
呼叫 getFootnotes 會導致對分頁的元素進行疊代。如果是大型分頁,請避免不必要地呼叫這個方法。
// 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[]:分頁的註腳。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getHeader()
擷取第一個分頁的標題區段,或擷取繫結至文件的指令碼目前分頁的標題區段。如要取得任何分頁的標題部分,請使用 DocumentTab.getHeader() 方法。
// 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());
回攻員
HeaderSection|null - 分頁的標題。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getId()
擷取文件的專屬 ID。文件 ID 會與 DocumentApp.openById() 搭配使用,開啟特定文件執行個體。
回攻員
String:文件的 ID。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getLanguage()
取得文件的語言代碼。這是文件編輯器「檔案」>「語言」中顯示的語言,可能與文件實際內容的語言不同。
回攻員
String|null:文件語言,或未定義時的 null。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getName()
擷取文件標題。
回攻員
String:文件標題。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRangeById(id)
在第一個分頁中取得具有指定 ID 的 NamedRange,或是取得繫結至文件的指令碼目前的分頁。如要在任何分頁中取得具有指定 ID 的 NamedRange,請使用 DocumentTab.getNamedRangeById(id) 方法。如果分頁中沒有這類 NamedRange,這個方法會傳回 null。名稱不一定會是唯一的,即使在不同分頁中也是如此;同一個分頁中的多個不同範圍可能會共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在分頁中是唯一的,就像 HTML 中的 ID 一樣。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
id | String | 範圍的 ID,在分頁中不得重複。 |
回攻員
NamedRange|null - 具有指定 ID 的 NamedRange,如果分頁中沒有這類範圍,則為 null。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRanges()
取得第一個分頁中的所有 NamedRange 物件,或取得繫結至文件的指令碼目前的分頁。如要取得任何分頁中的所有 NamedRange 物件,請使用 DocumentTab.getNamedRanges() 方法。
任何存取分頁的指令碼都可以存取 NamedRange。為避免指令碼之間發生非預期的衝突,建議您在範圍名稱加上專屬字串前置字元。
回攻員
NamedRange[]:分頁中的 NamedRange 物件陣列,可能包含多個名稱相同的範圍。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNamedRanges(name)
在第一個分頁中取得具有指定名稱的所有 NamedRange 物件,或是取得與文件繫結的指令碼所屬的有效分頁。如要取得任何分頁中的所有 NamedRange 物件,請使用 DocumentTab.getNamedRanges(name) 方法。名稱不一定會是唯一的,即使是跨分頁也一樣;同一個分頁中的多個不同範圍可能會共用相同名稱,就像 HTML 中的類別一樣。相較之下,ID 在分頁中是唯一的,就像 HTML 中的 ID 一樣。
任何存取文件的指令碼都可以存取 NamedRange。為避免指令碼之間發生非預期的衝突,建議您在範圍名稱加上專屬字串前置字元。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
name | String | 範圍的名稱 (不一定不得重複)。 |
回攻員
NamedRange[]:具有指定名稱的分頁中的 NamedRange 物件陣列。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getSelection()
取得現用分頁中使用者選取的內容。指令碼只能存取執行指令碼的使用者選取的內容,且指令碼必須繫結至文件。
// 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
getSupportedLanguageCodes()
取得 Google 文件檔案支援的所有語言代碼。
回攻員
String[]:語言代碼陣列。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getTab(tabId)
getTabs()
取得文件中所有未巢狀化的 Tab。
分頁可以包含子分頁,也就是巢狀分頁。使用 Tab.getChildTabs() 即可存取子項分頁。
回攻員
Tab[]:文件中所有 Tab 的清單。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getUrl()
擷取存取目前文件的網址。
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
getViewers()
newPosition(element, offset)
建立新的 Position,這是指分頁中的位置,相對於第一個分頁中的特定元素,或是繫結至文件的指令碼所屬的活動分頁。如要建立與任何分頁中位置相關的 Position,請使用 DocumentTab.newPosition(element, offset) 方法。使用者游標會以 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
newRange()
建立建構工具,用於從第一個分頁中的分頁元素建構 Range 物件,或從繫結至文件的指令碼所屬的現用分頁建構物件。如要建立建構工具,從任何分頁中的分頁元素建構 DocumentRange 物件,請使用 DocumentTab.newRange() 方法。
// 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());
回攻員
RangeBuilder:新的建構工具。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeEditor(emailAddress)
從 Document 的編輯者清單中移除指定使用者。如果使用者屬於具有一般存取權的使用者類別,例如 Document 是與使用者的整個網域共用,或是 Document 位於使用者可存取的共用雲端硬碟中,這個方法就無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從檢視者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
email | String | 要移除的使用者電子郵件地址。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeEditor(user)
從 Document 的編輯者清單中移除指定使用者。如果使用者屬於具有一般存取權的使用者類別,例如 Document 是與使用者的整個網域共用,或是 Document 位於使用者可存取的共用雲端硬碟中,這個方法就無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從檢視者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
user | User | 要移除的使用者代表。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeViewer(emailAddress)
從 Document 的觀眾和留言者清單中移除指定使用者。如果使用者是編輯者,而非檢視者或加註者,這個方法不會有任何作用。如果使用者屬於具有一般存取權的使用者類別 (例如 Document 與使用者的整個網域共用,或 Document 位於使用者可存取的共用雲端硬碟中),這個方法也無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從編輯者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
email | String | 要移除的使用者電子郵件地址。 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeViewer(user)
從 Document 的觀眾和留言者清單中移除指定使用者。如果使用者是編輯者而非檢視者,這個方法不會生效。如果使用者屬於具有一般存取權的使用者類別 (例如 Document 與使用者的整個網域共用,或 Document 位於使用者可存取的共用雲端硬碟中),這個方法也無法禁止使用者存取 Document。
如果是雲端硬碟檔案,系統也會從編輯者清單中移除使用者。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
user | User | 要移除的使用者代表。 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
saveAndClose()
儲存目前的 Document。清除並套用待處理的更新。
指令碼執行完畢後,系統會自動為每個開啟的可編輯 saveAndClose()叫用 Document 方法。
已結案的 Document 無法編輯。使用 DocumentApp.openById() 重新開啟特定文件進行編輯。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setActiveTab(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
setCursor(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
setLanguage(languageCode)
設定文件的語言代碼。這是文件編輯器「檔案」>「語言」中顯示的語言,可能與文件實際內容的語言不同。使用 getSupportedLanguageCodes() 取得所有有效的語言代碼。
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
language | String | 語言代碼。 |
回攻員
Document - This Document,用於鏈結。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setName(name)
setSelection(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