リッチテキストや表やリストなどの要素を含むドキュメント。
ドキュメントは、DocumentApp
を使用して開いたり作成したりできます。
// Open a document by ID. var doc = DocumentApp.openById("<my-id>"); // Create and open a document. doc = DocumentApp.create("Document Title");
Methods
メソッド | 戻り値の型 | 概要 |
---|---|---|
addBookmark(position) | Bookmark | 指定された Position に Bookmark を追加します。 |
addEditor(emailAddress) | Document | Document の編集者のリストに、指定されたユーザーを追加します。 |
addEditor(user) | Document | Document の編集者のリストに、指定されたユーザーを追加します。 |
addEditors(emailAddresses) | Document | 指定したユーザーの配列を Document の編集者のリストに追加します。 |
addFooter() | FooterSection | ドキュメント フッター セクションを追加します(存在しない場合)。 |
addHeader() | HeaderSection | ドキュメント ヘッダー セクションを追加します(存在しない場合)。 |
addNamedRange(name, range) | NamedRange | NamedRange を追加しました。これは、後で取得するための名前と ID を持つ Range です。 |
addViewer(emailAddress) | Document | Document の閲覧者リストに特定のユーザーを追加します。 |
addViewer(user) | Document | Document の閲覧者リストに特定のユーザーを追加します。 |
addViewers(emailAddresses) | Document | 指定したユーザーの配列を Document の閲覧者リストに追加します。 |
getAs(contentType) | Blob | 指定された型の blob として、現在の Document コンテンツを取得します。 |
getBlob() | Blob | 現在の Document コンテンツを blob として取得します。 |
getBody() | Body | アクティブ ドキュメントの Body を取得します。 |
getBookmark(id) | Bookmark | 指定された ID の Bookmark を取得します。 |
getBookmarks() | Bookmark[] | ドキュメント内のすべての Bookmark オブジェクトを取得します。 |
getCursor() | Position | アクティブ ドキュメント内のユーザーのカーソルを取得します。 |
getEditors() | User[] | この Document の編集者のリストを取得します。 |
getFooter() | FooterSection | ドキュメントのフッター セクションを取得します(存在する場合)。 |
getFootnotes() | Footnote[] | ドキュメント本文内のすべての Footnote 要素を取得します。 |
getHeader() | HeaderSection | ドキュメントのヘッダー セクションを取得します(存在する場合)。 |
getId() | String | ドキュメントの一意の識別子を取得します。 |
getLanguage() | String | ドキュメントの言語コードを取得します。 |
getName() | String | ドキュメントのタイトルを取得します。 |
getNamedRangeById(id) | NamedRange | 指定された ID の NamedRange を取得します。 |
getNamedRanges() | NamedRange[] | ドキュメント内のすべての NamedRange オブジェクトを取得します。 |
getNamedRanges(name) | NamedRange[] | 指定された名前のドキュメント内のすべての NamedRange オブジェクトを取得します。 |
getSelection() | Range | アクティブ ドキュメント内のユーザーの選択を取得します。 |
getSupportedLanguageCodes() | String[] | Google ドキュメント ファイルでサポートされているすべての言語コードを取得します。 |
getUrl() | String | 現在のドキュメントにアクセスするための URL を取得します。 |
getViewers() | User[] | この Document の閲覧者とコメント投稿者のリストを取得します。 |
newPosition(element, offset) | Position | 新しい Position を作成します。これは、特定の要素を基準に、ドキュメント内の場所への参照です。 |
newRange() | RangeBuilder | ドキュメント要素から Range オブジェクトを作成するために使用するビルダーを作成します。 |
removeEditor(emailAddress) | Document | Document の編集者のリストから指定されたユーザーを削除します。 |
removeEditor(user) | Document | Document の編集者のリストから指定されたユーザーを削除します。 |
removeViewer(emailAddress) | Document | Document の閲覧者とコメント投稿者のリストから指定されたユーザーを削除します。 |
removeViewer(user) | Document | Document の閲覧者とコメント投稿者のリストから指定されたユーザーを削除します。 |
saveAndClose() | void | 現在の Document を保存します。 |
setCursor(position) | Document | Position で指定されたアクティブ ドキュメント内のユーザーのカーソルを設定します。 |
setLanguage(languageCode) | Document | ドキュメントの言語コードを設定します。 |
setName(name) | Document | ドキュメントのタイトルを設定します。 |
setSelection(range) | Document | Range が設定された場合に、アクティブ ドキュメントでのユーザーの選択を設定します。 |
詳細なドキュメント
addBookmark(position)
指定された Position
に Bookmark
を追加します。
// 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('abc123456'); // Gets the document 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
addEditor(emailAddress)
Document
の編集者のリストに、指定されたユーザーを追加します。ユーザーがすでに閲覧者のリストに含まれていた場合、このメソッドはユーザーを閲覧者リストから昇格させます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | String | 追加するユーザーのメールアドレス。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addEditor(user)
addEditors(emailAddresses)
指定したユーザーの配列を Document
の編集者のリストに追加します。すでに閲覧者のリストに含まれていたユーザーがある場合、このメソッドはそのユーザーを視聴者のリストから昇格させます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddresses | String[] | 追加するユーザーのメールアドレスの配列。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addHeader()
ドキュメント ヘッダー セクションを追加します(存在しない場合)。
// 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('abc123456'); // Adds a header to the document. const header = doc.addHeader(); // Sets the header text to 'This is a header.' header.setText('This is a header');
復路
HeaderSection
- ドキュメント ヘッダー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addNamedRange(name, range)
NamedRange
を追加しました。これは、後で取得するための名前と ID を持つ Range
です。名前は一意であるとは限りません。HTML のクラスと同様に、同じドキュメント内の複数の範囲で同じ名前を使用できます。一方、ID は HTML の ID と同様に、ドキュメント内で一意です。NamedRange
をドキュメントに追加すると、その内容は変更できず、削除のみ可能になります。
ドキュメントにアクセスするスクリプトはすべて NamedRange
にアクセスできます。スクリプト間で意図しない競合が発生しないように、範囲名の前に一意の文字列を付加することを検討してください。
// Creates a named range that includes every table in the document. var doc = DocumentApp.getActiveDocument(); var rangeBuilder = doc.newRange(); var tables = doc.getBody().getTables(); for (var i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } doc.addNamedRange('Document tables', rangeBuilder.build());
パラメータ
名前 | 型 | 説明 |
---|---|---|
name | String | 範囲の名前は一意である必要はなく、1 ~ 256 文字にする必要があります。 |
range | Range | 名前に関連付ける要素の範囲。範囲は、有効な選択、検索結果、または newRange() を使用して手動で構築できます。 |
復路
NamedRange
- NamedRange
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
addViewer(emailAddress)
addViewer(user)
addViewers(emailAddresses)
指定したユーザーの配列を Document
の閲覧者リストに追加します。すでに編集者のリストに含まれていたユーザーがある場合、このメソッドはそのユーザーに影響はありません。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddresses | String[] | 追加するユーザーのメールアドレスの配列。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAs(contentType)
指定された型の blob として、現在の 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('abc123456'); // 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());
パラメータ
名前 | 型 | 説明 |
---|---|---|
contentType | String | 変換する MIME タイプ。現在のところ、'application/pdf' のみがサポートされています。 |
復路
Blob
- blob としての現在のドキュメント。
getBlob()
現在の 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('abc123456'); // Retrieves the current document's contents as a blob and logs it to the console. console.log(doc.getBlob().getContentType());
復路
Blob
- blob としての現在のドキュメント。
getBody()
有効なドキュメントの Body
を取得します。
ドキュメントには、さまざまな種類のセクション(HeaderSection
、FooterSection
など)を含めることができます。ドキュメントの有効なセクションは 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('abc123456'); // Gets the document 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
getBookmark(id)
指定された ID の Bookmark
を取得します。そのような 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('abc123456'); // Gets the bookmark by its ID. 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
getBookmarks()
ドキュメント内のすべての Bookmark
オブジェクトを取得します。
// 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('abc123456'); // Gets all of the bookmarks in the document. const bookmarks = doc.getBookmarks(); // Logs the number of bookmarks in the document to the console. console.log(bookmarks.length);
復路
Bookmark[]
- ドキュメント内の Bookmark
オブジェクトの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getCursor()
アクティブ ドキュメント内のユーザーのカーソルを取得します。スクリプトがアクセスできるのは、そのスクリプトを実行しているユーザーのカーソルだけです。これは、スクリプトがドキュメントにバインドされている場合に限ります。
// Insert some text at the cursor position and make it bold. var 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. var 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
getEditors()
getFootnotes()
ドキュメント本文内のすべての Footnote
要素を取得します。
getFootnotes
を呼び出すと、ドキュメントの要素が反復処理されます。サイズの大きいドキュメントの場合は、このメソッドを不必要に呼び出すことは避けてください。
// 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('abc123456'); // Gets the first footnote. 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
getHeader()
ドキュメントのヘッダー セクションを取得します(存在する場合)。
// 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('abc123456'); // Gets the text of the document's header and logs it to the console. console.log(doc.getHeader().getText());
復路
HeaderSection
- ドキュメント ヘッダー。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getId()
getLanguage()
getName()
getNamedRangeById(id)
指定された ID の NamedRange
を取得します。そのような NamedRange
が存在しない場合、このメソッドは null
を返します。名前は必ずしも一意ではありません。HTML のクラスと同様に、同じドキュメント内の異なる範囲には同じ名前を使用できます。一方、ID は HTML の ID と同様に、ドキュメント内で一意です。
パラメータ
名前 | 型 | 説明 |
---|---|---|
id | String | 範囲の ID(ドキュメント内で一意) |
復路
NamedRange
- 指定された ID を持つ NamedRange
、またはそのような範囲が存在しない場合は null
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNamedRanges()
ドキュメント内のすべての NamedRange
オブジェクトを取得します。
NamedRange
には、ドキュメントにアクセスするスクリプトからアクセスできます。スクリプト間で意図しない競合が発生しないように、範囲名の前に一意の文字列を付加することを検討してください。
復路
NamedRange[]
- ドキュメント内の NamedRange
オブジェクトの配列。同じ名前の複数の範囲が含まれている場合があります。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNamedRanges(name)
指定された名前のドキュメント内のすべての NamedRange
オブジェクトを取得します。名前は一意ではなく、HTML のクラスと同じように、同じドキュメント内の異なる範囲が同じ名前を持つ場合があります。一方、ID は HTML の ID と同様に、ドキュメント内で一意です。
NamedRange
には、ドキュメントにアクセスするスクリプトからアクセスできます。スクリプト間で意図しない競合が発生しないように、範囲名の前に一意の文字列を付加することを検討してください。
パラメータ
名前 | 型 | 説明 |
---|---|---|
name | String | 範囲の名前。一意とは限らない |
復路
NamedRange[]
- 指定した名前のドキュメント内の NamedRange
オブジェクトの配列
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSelection()
アクティブ ドキュメント内のユーザーの選択を取得します。スクリプトがアクセスできるのは、スクリプトを実行しているユーザーの選択と、スクリプトがドキュメントにバインドされている場合のみです。
// Display a dialog box that tells the user how many elements are included in the selection. var selection = DocumentApp.getActiveDocument().getSelection(); if (selection) { var 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
getSupportedLanguageCodes()
getUrl()
現在のドキュメントにアクセスするための URL を取得します。
var 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
getViewers()
newPosition(element, offset)
新しい Position
を作成します。これは、特定の要素を基準に、ドキュメント内の場所への参照です。ユーザーのカーソルは、特に Position
として表されます。
// Append a paragraph, then place the user's cursor after the first word of the new paragraph. var doc = DocumentApp.getActiveDocument(); var paragraph = doc.getBody().appendParagraph('My new paragraph.'); var 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
newRange()
ドキュメント要素から Range
オブジェクトを作成するために使用するビルダーを作成します。
// Change the user's selection to a range that includes every table in the document. var doc = DocumentApp.getActiveDocument(); var rangeBuilder = doc.newRange(); var tables = doc.getBody().getTables(); for (var i = 0; i < tables.length; i++) { rangeBuilder.addElement(tables[i]); } doc.setSelection(rangeBuilder.build());
復路
RangeBuilder
- 新しいビルダー
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeEditor(emailAddress)
Document
の編集者のリストから指定されたユーザーを削除します。このメソッドは、Document
がユーザーのドメイン全体と共有されている場合や、Document
がアクセスできる共有ドライブにある場合など、一般的なアクセス権を持つユーザーのクラスに属している場合、Document
へのアクセスをブロックしません。
ドライブ内のファイルの場合、閲覧者のリストからユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeEditor(user)
Document
の編集者のリストから指定されたユーザーを削除します。このメソッドは、Document
がユーザーのドメイン全体と共有されている場合や、Document
がアクセスできる共有ドライブにある場合など、一般的なアクセス権を持つユーザーのクラスに属している場合、Document
へのアクセスをブロックしません。
ドライブ内のファイルの場合、閲覧者のリストからユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeViewer(emailAddress)
Document
の閲覧者とコメント投稿者のリストから指定されたユーザーを削除します。ユーザーが閲覧者であれ、コメント投稿者でもありません。この方法では、Document
がユーザーのドメイン全体と共有されている場合、または Document
がアクセスできる共有ドライブにある場合など、一般的なアクセス権を持つユーザーのクラスに属している場合でも、Document
へのアクセスはブロックされません。
ドライブ ファイルの場合は、編集者のリストからユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeViewer(user)
Document
の閲覧者とコメント投稿者のリストから指定されたユーザーを削除します。ユーザーが閲覧者ではなく編集者の場合、このメソッドは何の効果も生じさせません。このメソッドは、Document
がユーザーのドメイン全体と共有されている場合や、Document
がアクセスできる共有ドライブにある場合など、一般的なアクセス権を持つユーザーのクラスに属している場合、Document
へのアクセスをブロックしません。
ドライブ ファイルの場合は、編集者のリストからユーザーが削除されます。
パラメータ
名前 | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
復路
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
saveAndClose()
現在の Document
を保存します。保留中の更新がフラッシュされて適用されます。
saveAndClose()
メソッドは、スクリプト実行の終了時に、編集可能な Document
ごとに自動的に呼び出されます。
閉じた Document
は編集できません。DocumentApp.openById()
を使用して、特定のドキュメントを編集用に再度開きます。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setCursor(position)
Position
で指定されたアクティブ ドキュメント内のユーザーのカーソルを設定します。スクリプトがアクセスできるのは、そのスクリプトを実行しているユーザーのカーソルだけです。これは、スクリプトがドキュメントにバインドされている場合に限ります。
// Append a paragraph, then place the user's cursor after the first word of the new paragraph. var doc = DocumentApp.getActiveDocument(); var paragraph = doc.getBody().appendParagraph('My new paragraph.'); var position = doc.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
setLanguage(languageCode)
ドキュメントの言語コードを設定します。これはドキュメント エディタの [File] > [Language] に表示される言語であり、ドキュメント内の実際の言語とは異なる場合があります。すべての有効な言語コードを取得するには getSupportedLanguageCodes()
を使用します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
languageCode | String | 言語コード。 |
復路
Document
- チェーン用の Document
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setName(name)
ドキュメントのタイトルを設定します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
name | String | 新しいドキュメントのタイトル |
復路
Document
- 現在のドキュメント
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setSelection(range)
Range
が設定された場合に、アクティブ ドキュメントでのユーザーの選択を設定します。スクリプトがアクセスできるのは、スクリプトを実行しているユーザーの選択と、スクリプトがドキュメントにバインドされている場合のみです。
// Change the user's selection to a range that includes every table in the document. var doc = DocumentApp.getActiveDocument(); var rangeBuilder = doc.newRange(); var tables = doc.getBody().getTables(); for (var 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