1 つ以上の Tab オブジェクトを含むドキュメント。各オブジェクトには、リッチテキストと、テーブルやリストなどの要素が含まれています。
ドキュメントは 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のBookmarkを最初のタブに追加します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブに追加します。 | 
| add | Document | 指定されたユーザーを Documentの編集者のリストに追加します。 | 
| add | Document | 指定されたユーザーを Documentの編集者のリストに追加します。 | 
| add | Document | 指定されたユーザーの配列を Documentの編集者のリストに追加します。 | 
| add | Footer | フッター セクションが存在しない場合は、最初のタブに追加します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブに追加します。 | 
| add | Header | ヘッダー セクションが存在しない場合は、最初のタブに追加します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブに追加します。 | 
| add | Named | Namedを追加します。これは、後で取得するために使用する名前と ID を持つRangeで、最初のタブに追加します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブに追加します。 | 
| add | Document | 指定したユーザーを Documentの視聴者のリストに追加します。 | 
| add | Document | 指定したユーザーを Documentの視聴者のリストに追加します。 | 
| add | Document | 指定されたユーザーの配列を Documentの視聴者のリストに追加します。 | 
| get | Tab | ドキュメント内で現在アクティブなユーザーの Tabを取得します。 | 
| get | Blob | 現在の Documentコンテンツを指定されたタイプの blob として取得します。 | 
| get | Blob | 現在の Documentの内容を blob として取得します。 | 
| get | Body | 最初のタブの Bodyを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブのDocumentを取得します。 | 
| get | Bookmark | 最初のタブで指定された ID の Bookmarkを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブを取得します。 | 
| get | Bookmark[] | 最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブ内のすべての Bookmarkオブジェクトを取得します。 | 
| get | Position | アクティブなタブ内のユーザーのカーソルを取得します。 | 
| get | User[] | この Documentの編集者のリストを取得します。 | 
| get | Footer | 最初のタブのフッター セクションを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブのフッター セクションを取得します。 | 
| get | Footnote[] | 最初のタブの body 内のすべての Footnote要素を取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブの body を取得します。 | 
| get | Header | 最初のタブのヘッダー セクションを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブのヘッダー セクションを取得します。 | 
| get | String | ドキュメントの一意の ID を取得します。 | 
| get | String | ドキュメントの言語コードを取得します。 | 
| get | String | ドキュメントのタイトルを取得します。 | 
| get | Named | 最初のタブで指定された ID の Namedを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブを取得します。 | 
| get | Named | 最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブ内のすべての Namedオブジェクトを取得します。 | 
| get | Named | 最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブで、指定された名前のすべての Namedオブジェクトを取得します。 | 
| get | Range | アクティブなタブでユーザーが選択した内容を取得します。 | 
| get | String[] | Google ドキュメント ファイルでサポートされているすべての言語コードを取得します。 | 
| get | Tab | 指定された ID の Tabを取得します。 | 
| get | Tab[] | ドキュメントに含まれるネストされていないすべての Tabを取得します。 | 
| get | String | 現在のドキュメントにアクセスするための URL を取得します。 | 
| get | User[] | この Documentの閲覧者とコメント投稿者のリストを取得します。 | 
| new | Position | 新しい Positionを作成します。これは、最初のタブの特定の要素を基準とするタブ内の位置への参照です。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブを基準とします。 | 
| new | Range | 最初のタブのタブ要素から Rangeオブジェクトを作成するために使用されるビルダーを作成します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブから作成します。 | 
| remove | Document | 指定されたユーザーを Documentの編集者のリストから削除します。 | 
| remove | Document | 指定されたユーザーを Documentの編集者のリストから削除します。 | 
| remove | Document | 指定したユーザーを Documentの閲覧者とコメント投稿者のリストから削除します。 | 
| remove | Document | 指定したユーザーを Documentの閲覧者とコメント投稿者のリストから削除します。 | 
| save | void | 現在の Documentを保存します。 | 
| set | void | 現在のドキュメントでユーザーが選択した Tabを、指定された ID のタブに設定します。 | 
| set | Document | Positionを指定して、ユーザーのカーソルを設定します。 | 
| set | Document | ドキュメントの言語コードを設定します。 | 
| set | Document | ドキュメントのタイトルを設定します。 | 
| set | Document | Rangeを指定して、アクティブなタブでユーザーの選択を設定します。 | 
詳細なドキュメント
add
指定された 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 - 新しいブックマーク。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
add
add
add
add
ヘッダー セクションが存在しない場合は、最初のタブに追加します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブに追加します。タブにヘッダー セクションを追加するには、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 - タブのヘッダー。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
add
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。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
add
add
add
get
ドキュメント内で現在アクティブなユーザーの 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。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
現在の Document コンテンツを指定されたタイプの blob として取得します。
// 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
現在の Document の内容を blob として取得します。
// 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 を取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブの 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 - タブの本文セクション。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブで指定された 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 - 指定された ID の Bookmark。タブ内にそのような Bookmark が存在しない場合は null。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブ内のすべての 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 オブジェクトの配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
アクティブなタブ内のユーザーのカーソルを取得します。スクリプトは、スクリプトを実行しているユーザーのカーソルにのみアクセスできます。ただし、スクリプトがドキュメントにバインドされている場合に限られます。
// 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 です。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
get
最初のタブの body 内のすべての Footnote 要素を取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブの body を取得します。任意のタブ内のすべての脚注を取得するには、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[] - タブの脚注。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブのヘッダー セクションを取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブのヘッダー セクションを取得します。タブのヘッダー セクションを取得するには、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 - タブのヘッダー。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
ドキュメントの一意の ID を取得します。ドキュメント ID は、Document とともに使用して、特定のドキュメント インスタンスを開くために使用されます。
戻る
String - ドキュメントの ID。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
ドキュメントの言語コードを取得します。これは、ドキュメント エディタの [ファイル > 言語] に表示される言語です。ドキュメントに含まれる実際の言語とは異なる場合があります。
戻る
String - ドキュメントの言語。定義されていない場合は null。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
ドキュメントのタイトルを取得します。
戻る
String - ドキュメントのタイトル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブで指定された ID の Named を取得します。ドキュメントにバインドされているスクリプトの場合は、アクティブなタブで取得します。任意のタブで指定された ID の Named を取得するには、Document メソッドを使用します。タブにそのような Named が存在しない場合、このメソッドは null を返します。名前は、タブ間で一意である必要はありません。HTML のクラスと同様に、同じタブ内の複数の範囲で同じ名前が使用される場合があります。一方、ID はタブ内で一意です(HTML の ID と同様に)。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| id | String | タブ内で一意の範囲の ID。 | 
戻る
Named - 指定された ID の Named。タブにそのような範囲が存在しない場合は null。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブ内のすべての Named オブジェクトを取得します。任意のタブ内のすべての Named オブジェクトを取得するには、Document メソッドを使用します。
Named には、タブにアクセスするすべてのスクリプトからアクセスできます。スクリプト間で意図しない競合が発生しないようにするには、範囲名に一意の文字列を接頭辞として追加することを検討してください。
戻る
Named - タブ内の Named オブジェクトの配列。同じ名前の範囲が複数含まれている場合があります。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
最初のタブ、またはドキュメントにバインドされているスクリプトの場合はアクティブなタブで、指定された名前のすべての Named オブジェクトを取得します。任意のタブ内のすべての Named オブジェクトを取得するには、Document メソッドを使用します。名前は、タブ間で一意である必要はありません。HTML のクラスと同様に、同じタブ内の複数の範囲で同じ名前が使用される場合があります。一方、ID はタブ内で一意です(HTML の ID など)。
Named には、ドキュメントにアクセスするすべてのスクリプトからアクセスできます。スクリプト間で意図しない競合が発生しないようにするには、範囲名に一意の文字列を接頭辞として追加することを検討してください。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| name | String | 範囲の名前(一意である必要はありません)。 | 
戻る
Named - 指定された名前のタブ内の Named オブジェクトの配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
アクティブなタブでユーザーが選択した内容を取得します。スクリプトは、スクリプトを実行しているユーザーの選択範囲にのみアクセスできます。ただし、スクリプトがドキュメントにバインドされている場合に限られます。
// 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 です。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
Google ドキュメント ファイルでサポートされているすべての言語コードを取得します。
戻る
String[] - 言語コードの配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
指定された ID の Tab を取得します。そのような Tab が存在しない場合、このメソッドは null を返します。任意のネストレベルのタブにアクセスできます。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| tab | String | 取得するタブの ID。 | 
戻る
Tab - 指定された ID の Tab。そのような Tab が存在しない場合は null。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
ドキュメントに含まれるネストされていないすべての Tab を取得します。
タブには、子タブ(別のタブ内にネストされたタブ)を含めることができます。子タブには Tab.getChildTabs() を使用してアクセスできます。
戻る
Tab[] - ドキュメントに含まれるすべての Tab のリスト。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
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 - 現在のドキュメントにアクセスするための URL。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
get
new
新しい 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。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
new
最初のタブのタブ要素から 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 - 新しいビルダー。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
remove
指定されたユーザーを Document の編集者のリストから削除します。この方法では、一般アクセス権を持つユーザー クラスに属するユーザーが Document にアクセスできないようにはなりません。たとえば、Document がユーザーのドメイン全体と共有されている場合や、Document がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは閲覧者のリストからも削除されます。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| email | String | 削除するユーザーのメールアドレス。 | 
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
remove
指定されたユーザーを Document の編集者のリストから削除します。この方法では、一般アクセス権を持つユーザー クラスに属するユーザーが Document にアクセスできないようにはなりません。たとえば、Document がユーザーのドメイン全体と共有されている場合や、Document がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは閲覧者のリストからも削除されます。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| user | User | 削除するユーザーを表す。 | 
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
remove
指定したユーザーを Document の閲覧者とコメント投稿者のリストから削除します。ユーザーが視聴者やコメント投稿者ではなく編集者である場合、この方法は効果がありません。また、この方法では、一般アクセス権を持つユーザー クラスに属しているユーザーが Document にアクセスできないようにはなりません。たとえば、Document がユーザーのドメイン全体と共有されている場合や、Document がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは編集者のリストからも削除されます。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| email | String | 削除するユーザーのメールアドレス。 | 
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
remove
指定したユーザーを Document の閲覧者とコメント投稿者のリストから削除します。ユーザーが閲覧者ではなく編集者である場合、このメソッドは効果がありません。また、この方法では、一般的なアクセス権を持つユーザー クラスに属しているユーザーが Document にアクセスできないようにはなりません。たとえば、Document がユーザーのドメイン全体と共有されている場合や、Document がユーザーがアクセスできる共有ドライブにある場合などです。
ドライブ ファイルの場合、この操作により、ユーザーは編集者のリストからも削除されます。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| user | User | 削除するユーザーを表す。 | 
戻る
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
save
現在の Document を保存します。保留中のアップデートがフラッシュされ、適用されます。
save メソッドは、開いている編集可能な Document ごとに、スクリプトの実行の終了時に自動的に呼び出されます。
クローズ済みの Document は編集できません。Document を使用して、特定のドキュメントを再度開いて編集します。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
set
現在のドキュメントでユーザーが選択した 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。 | 
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
set
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 - チェーン用の Document。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
set
ドキュメントの言語コードを設定します。これは、ドキュメント エディタの [ファイル > 言語] に表示される言語です。ドキュメントに含まれる実際の言語とは異なる場合があります。get を使用して、有効な言語コードをすべて取得します。
パラメータ
| 名前 | 型 | 説明 | 
|---|---|---|
| language | String | 言語コード。 | 
戻る
Document - チェーン用の Document。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents
set
set
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 - チェーン用の Document。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
- 
https://www.googleapis.com/auth/documents.currentonly
- 
https://www.googleapis.com/auth/documents