文件服務會建立並開啟可編輯的 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)
get
傳回指令碼容器繫結的文件。如要與指令碼未繫結容器的文件互動,請改用 open 或 open。
// 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
get
會傳回文件使用者介面環境的例項,讓指令碼可新增選單、對話方塊和側欄等功能。指令碼只能與開啟文件的目前例項 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:此文件的使用者介面環境的例項
open
傳回含有指定 ID 的文件。如果指令碼與文件的容器相連,請改用 get。
// 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
open
開啟並傳回含有指定網址的文件。如果指令碼與文件的容器綁定,請改用 get。
// 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