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