ドキュメント サービスで Documents
が作成され、編集できるようになります。
// Open a document by ID. var doc = DocumentApp.openById('DOCUMENT_ID_GOES_HERE'); // Create and open a document. doc = DocumentApp.create('Document Name');
Properties
プロパティ | 種類 | 説明 |
---|---|---|
Attribute | Attribute | Attribute 列挙型。 |
ElementType | ElementType | ElementType 列挙型。 |
FontFamily |
| 列挙型。 |
GlyphType | GlyphType | GlyphType 列挙型。 |
HorizontalAlignment | HorizontalAlignment | HorizontalAlignment 列挙型。 |
ParagraphHeading | ParagraphHeading | ParagraphHeading 列挙型。 |
PositionedLayout | PositionedLayout | PositionedLayout 列挙型。 |
TextAlignment | TextAlignment | TextAlignment 列挙型。 |
VerticalAlignment | VerticalAlignment | VerticalAlignment 列挙型。 |
Methods
方法 | 戻り値の型 | 概要 |
---|---|---|
create(name) | Document | 新しいドキュメントを作成して返します。 |
getActiveDocument() | Document | スクリプトがコンテナにバインドされているドキュメントを返します。 |
getUi() | Ui | スクリプトがユーザー インターフェース環境のインスタンスを返します。スクリプトにより、スクリプトはメニュー、ダイアログ、サイドバーなどの機能を追加できます。 |
openById(id) | Document | 指定された ID のドキュメントを返します。 |
openByUrl(url) | Document | 指定された URL にあるドキュメントを開いて返します。 |
詳細なドキュメント
create(name)
getActiveDocument()
スクリプトがコンテナにバインドされているドキュメントを返します。スクリプトがコンテナにバインドされていないドキュメントを操作するには、代わりに openById(id)
または openByUrl(url)
を使用します。
// Get the document to which this script is bound. var doc = DocumentApp.getActiveDocument();
戻る
Document
- ドキュメント インスタンス
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
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. var doc = DocumentApp.openById('DOCUMENT_ID_GOES_HERE');
パラメータ
名前 | 型 | 説明 |
---|---|---|
id | String | 開くドキュメントの ID |
戻る
Document
- ドキュメント インスタンス
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents
openByUrl(url)
指定された URL にあるドキュメントを開いて返します。スクリプトがコンテナにバインドされている場合は、代わりに getActiveDocument()
を使用します。
// Open a document by URL. var doc = DocumentApp.openByUrl( 'https://docs.google.com/document/d/1234567890abcdefghijklmnopqrstuvwxyz_a1b2c3/edit');
パラメータ
名前 | 型 | 説明 |
---|---|---|
url | String | 開くドキュメントの URL |
戻る
Document
- ドキュメント インスタンス
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents