文件服務會建立並開啟 Documents,供您編輯。
// Open a document by ID. // TODO(developer): Replace the ID with your own. let doc = DocumentApp.openById('DOCUMENT_ID'); // Create and open a document. doc = DocumentApp.create('Document Name');
屬性
| 屬性 | 類型 | 說明 |
|---|---|---|
Attribute | Attribute | Attribute 列舉。 |
Element | Element | Element 列舉。 |
Font | | 列舉。 |
Glyph | Glyph | Glyph 列舉。 |
Horizontal | Horizontal | Horizontal 列舉。 |
Paragraph | Paragraph | Paragraph 列舉。 |
Positioned | Positioned | Positioned 列舉。 |
Text | Text | Text 列舉。 |
Vertical | Vertical | Vertical 列舉。 |
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
create(name) | Document | 建立並傳回新文件。 |
get | Document | 傳回指令碼繫結的容器文件。 |
get | Ui | 傳回文件使用者介面環境的執行個體,允許指令碼新增選單、對話方塊和側欄等功能。 |
open | Document | 傳回含有指定 ID 的文件。 |
open | Document | 開啟並傳回具有指定網址的文件。 |
內容詳盡的說明文件
create(name)
getActiveDocument()
傳回指令碼繫結的容器文件。如要與指令碼未繫結的文件互動,請改用 openById(id) 或 openByUrl(url)。
// Get the document to which this script is bound. const doc = DocumentApp.getActiveDocument();
回攻員
Document - 文件例項
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getUi()
傳回文件使用者介面環境的執行個體,允許指令碼新增選單、對話方塊和側欄等功能。指令碼只能與目前開啟文件執行個體的 UI 互動,且必須繫結至該文件。詳情請參閱選單和對話方塊與側欄指南。
// Add a custom menu to the active document, including a separator and a // sub-menu. function onOpen(e) { DocumentApp.getUi() .createMenu('My Menu') .addItem('My menu item', 'myFunction') .addSeparator() .addSubMenu( DocumentApp.getUi() .createMenu('My sub-menu') .addItem('One sub-menu item', 'mySecondFunction') .addItem('Another sub-menu item', 'myThirdFunction'), ) .addToUi(); }
回攻員
Ui:這個文件使用者介面環境的執行個體
openById(id)
傳回含有指定 ID 的文件。如果指令碼是繫結至文件的容器,請改用 getActiveDocument()。
// Open a document by ID. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('DOCUMENT_ID');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
id | String | 要開啟的文件 ID。 |
回攻員
Document:文件例項。
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents
openByUrl(url)
開啟並傳回具有指定網址的文件。如果指令碼繫結至文件,請改用 getActiveDocument()。
// Open a document by URL. const doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/1234567890abcdefghijklmnopqrstuvwxyz_a1b2c3/edit', );
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
url | String | 要開啟的文件網址 |
回攻員
Document - 文件例項
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
https://www.googleapis.com/auth/documents