段落を表す要素。Paragraph
には、Equation
、Footnote
、HorizontalRule
、InlineDrawing
、InlineImage
、PageBreak
、Text
要素を含めることができます。ドキュメント構造について詳しくは、Google ドキュメントの拡張ガイドをご覧ください。
Paragraphs
に改行文字を含めることはできません。改行文字(「\n」)は改行文字(Waze)に変換されます。
var body = DocumentApp.getActiveDocument().getBody(); // Append a document header paragraph. var header = body.appendParagraph("A Document"); header.setHeading(DocumentApp.ParagraphHeading.HEADING1); // Append a section header paragraph. var section = body.appendParagraph("Section 1"); section.setHeading(DocumentApp.ParagraphHeading.HEADING2); // Append a regular paragraph. body.appendParagraph("This is a typical paragraph.");
Methods
詳細なドキュメント
addPositionedImage(image)
指定された blob から新しい PositionedImage
を作成して挿入します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the specified image URL. const image = UrlFetchApp.fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-24dp/logo_apps_script_color_1x_web_24dp.png'); // Adds the image to the document, anchored to the first paragraph. paragraph.addPositionedImage(image);
パラメータ
Name | 型 | 説明 |
---|---|---|
image | BlobSource | 画像データ。 |
復路
PositionedImage
- 新たに配置された画像。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendHorizontalRule()
新しい HorizontalRule
を作成して追加します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a horizontal line under the first paragraph. paragraph.appendHorizontalRule();
復路
HorizontalRule
- 新しい水平ルール。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
指定された blob から新しい InlineImage
を作成して追加します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the image from the specified image URL. const image = UrlFetchApp .fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-96dp/logo_apps_script_color_1x_web_96dp.png'); // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
パラメータ
Name | 型 | 説明 |
---|---|---|
image | BlobSource | 画像データ。 |
復路
InlineImage
- 追加された画像。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
指定された InlineImage
を追加します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Makes a copy of the first image in the body. const image = body.getImages()[0].copy();; // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
パラメータ
Name | 型 | 説明 |
---|---|---|
image | InlineImage | 画像データ。 |
復路
InlineImage
- 追加された画像。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak()
新しい PageBreak
を作成して追加します。
注: PageBreaks
は TableCells
に含めることはできません。現在の要素がテーブルセルに含まれている場合、例外がスローされます。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. paragraph.appendPageBreak();
復路
PageBreak
- 新しい改ページ要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak(pageBreak)
指定された PageBreak
を追加します。
注: PageBreaks
を TableCells
に含めることはできません。現在の要素がテーブルセルに存在している場合、スクリプトは例外をスローします。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. const pageBreak = paragraph.appendPageBreak(); // Makes a copy of the page break. const newPageBreak = pageBreak.copy(); // Adds the copied page break to the paragraph. paragraph.appendPageBreak(newPageBreak);
パラメータ
Name | 型 | 説明 |
---|---|---|
pageBreak | PageBreak | 追加する改ページ。 |
復路
PageBreak
- 追加された改ページ要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
指定された内容の新しい Text
要素を作成して追加します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a string to the paragraph. paragraph.appendText('This is a new sentence.');
パラメータ
Name | 型 | 説明 |
---|---|---|
text | String | テキストの内容。 |
復路
Text
- 新しいテキスト要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
指定された Text
要素を追加します。
// 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 text from the first paragraph in the body. const paragraph1 = body.getParagraphs()[0]; const text = paragraph1.getText(); // Gets the third paragraph in the body. const paragraph3 = body.getParagraphs()[2]; // Adds the text from the first paragraph to the third paragraph. paragraph3.appendText(text);
パラメータ
Name | 型 | 説明 |
---|---|---|
text | Text | 追加するテキスト要素。 |
復路
Text
- 追加されたテキスト要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
clear()
copy()
現在の要素のデタッチされたディープコピーを返します。
要素内の子要素もすべてコピーされます。新しい要素に親は設定されていません。
復路
Paragraph
- 新しいコピー。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
editAsText()
編集するために、現在の要素の Text
バージョンを取得します。
要素のコンテンツをリッチテキストとして操作するには、editAsText
を使用します。editAsText
モードでは、テキスト以外の要素(InlineImage
や HorizontalRule
など)は無視されます。
削除されたテキスト範囲内に完全に含まれる子要素は、要素から削除されます。
var body = DocumentApp.getActiveDocument().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, "An editAsText sample."); body.insertHorizontalRule(0); body.insertParagraph(0, "An example."); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
復路
Text
- 現在の要素のテキスト バージョン
findElement(elementType)
要素のコンテンツで指定されたタイプの子孫を検索します。
パラメータ
Name | 型 | 説明 |
---|---|---|
elementType | ElementType | 検索する要素のタイプ |
復路
RangeElement
- 検索要素の位置を示す検索結果
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findElement(elementType, from)
指定されたコンテンツ(指定されたタイプの子孫)の要素を、指定された RangeElement
から検索します。
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Define the search parameters. var searchType = DocumentApp.ElementType.PARAGRAPH; var searchHeading = DocumentApp.ParagraphHeading.HEADING1; var searchResult = null; // Search until the paragraph is found. while (searchResult = body.findElement(searchType, searchResult)) { var par = searchResult.getElement().asParagraph(); if (par.getHeading() == searchHeading) { // Found one, update and stop. par.setText('This is the first header.'); return; } }
パラメータ
Name | 型 | 説明 |
---|---|---|
elementType | ElementType | 検索する要素のタイプ |
from | RangeElement | 検索元の検索結果 |
復路
RangeElement
- 検索要素の次の位置を示す検索結果
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
正規表現を使用して、要素のコンテンツで指定されたテキスト パターンを検索します。
JavaScript の正規表現機能のサブセット(キャプチャ グループやモード修飾子など)は、完全にはサポートされていません。
指定された正規表現パターンは、現在の要素に含まれるテキスト ブロックごとに独立して照合されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
searchPattern | String | 検索するパターンを指定します |
復路
RangeElement
- 検索テキストの位置を示す検索結果。一致がない場合は null 。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
特定のコンテンツから、指定されたテキスト パターンの要素のコンテンツを検索します。
JavaScript の正規表現機能のサブセット(キャプチャ グループやモード修飾子など)は、完全にはサポートされていません。
指定された正規表現パターンは、現在の要素に含まれるテキスト ブロックごとに独立して照合されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
searchPattern | String | 検索するパターンを指定します |
from | RangeElement | 検索元の検索結果 |
復路
RangeElement
- 検索テキストの次の位置を示す検索結果。一致がない場合は null 。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAlignment()
HorizontalAlignment
を取得します。
// 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 first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Sets the horizontal alignment to left for the first paragraph. paragraph.setAlignment(DocumentApp.HorizontalAlignment.LEFT); // Gets the horizontal alignment of the first paragraph and logs it to the console. console.log(paragraph.getAlignment().toString());
復路
HorizontalAlignment
- アライメント。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
要素の属性を取得します。
その結果、各要素名が DocumentApp.Attribute
列挙型のアイテムに対応する、有効な要素属性ごとにプロパティを含むオブジェクトが作成されます。
var body = DocumentApp.getActiveDocument().getBody(); // Append a styled paragraph. var par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. var atts = par.getAttributes(); // Log the paragraph attributes. for (var att in atts) { Logger.log(att + ":" + atts[att]); }
復路
Object
- 要素の属性。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChild(childIndex)
指定された子インデックスの子要素を取得します。
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document. var firstChild = body.getChild(0); // If it's a paragraph, set its contents. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { firstChild.asParagraph().setText("This is the first paragraph."); }
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 取得する子要素のインデックス |
復路
Element
- 指定したインデックスの子要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChildIndex(child)
指定された子要素の子インデックスを取得します。
パラメータ
Name | 型 | 説明 |
---|---|---|
child | Element | インデックスを取得する子要素 |
復路
Integer
- 子インデックス
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getHeading()
ParagraphHeading
を取得します。
// 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(); // Adds a paragraph to the body. const paragraph = body.appendParagraph('Title heading'); // Sets the paragraph heading style to 'Title.' paragraph.setHeading(DocumentApp.ParagraphHeading.TITLE); // Gets the heading style and logs it to the console. console.log(paragraph.getHeading().toString());
復路
ParagraphHeading
- 見出し。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentEnd()
getIndentFirstLine()
getIndentStart()
getLineSpacing()
getLinkUrl()
getNextSibling()
要素の次の兄弟要素を取得します。
次の兄弟は同じ親を持ち、現在の要素に従います。
復路
Element
- 次の兄弟要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNumChildren()
子の数を取得します。
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Log the number of elements in the document. Logger.log("There are " + body.getNumChildren() + " elements in the document body.");
復路
Integer
- 子の数
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
要素の親要素を取得します。
親要素には現在の要素が含まれます。
復路
ContainerElement
- 親要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImage(id)
画像の ID で PositionedImage
を取得します。
パラメータ
Name | 型 | 説明 |
---|---|---|
id | String | 画像 ID |
復路
PositionedImage
- 配置された画像
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImages()
段落に固定されているすべての PositionedImage
オブジェクトを取得します。
復路
PositionedImage[]
- 配置された画像のリスト
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
要素の前の兄弟要素を取得します。
前の兄弟は同じ親を持ち、現在の要素の前にあります。
復路
Element
- 前の兄弟要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingAfter()
getSpacingBefore()
getText()
getTextAlignment()
テキストの配置を取得します。配置に使用できるタイプは DocumentApp.TextAlignment.NORMAL
、DocumentApp.TextAlignment.SUBSCRIPT
、DocumentApp.TextAlignment.SUPERSCRIPT
です。
復路
TextAlignment
- テキストの配置タイプ。テキストに複数の種類のテキストの配置が含まれている場合や、テキストの配置が一度も設定されていない場合は null
です。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
要素の ElementType
を取得します。
getType()
を使用して、特定の要素の正確な型を判別します。
var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document body. var firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
復路
ElementType
- 要素タイプ。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertHorizontalRule(childIndex)
HorizontalRule
を作成して、指定したインデックスに挿入します。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
復路
HorizontalRule
- 新しい水平ルール要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
指定された blob から、指定されたインデックスに新しい InlineImage
を作成して挿入します。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
image | BlobSource | 画像データ |
復路
InlineImage
- 挿入されたインライン画像要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
指定されたインデックスに指定された InlineImage
を挿入します。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
image | InlineImage | 画像データ |
復路
InlineImage
- 挿入されたインライン画像要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex)
新しい PageBreak
を作成して、指定されたインデックスに挿入します。
注: PageBreaks
は TableCells
に含めることはできません。現在の要素が表のセルに含まれている場合は、例外がスローされます。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
復路
PageBreak
- 新しい改ページ要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex, pageBreak)
指定されたインデックスに指定された PageBreak
を挿入します。
注: PageBreaks
は TableCells
に含めることはできません。現在の要素が表のセルに含まれている場合は、例外がスローされます。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
pageBreak | PageBreak | 挿入するページ区切り |
復路
PageBreak
- 挿入された改ページ要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
指定されたインデックスに新しいテキスト要素を作成して挿入します。
パラメータ
Name | 型 | 説明 |
---|---|---|
childIndex | Integer | 要素を挿入するインデックス |
text | String | テキストの内容 |
復路
Text
- 新しいテキスト要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
isAtDocumentEnd()
要素が Document
の最後にあるかどうかを判断します。
復路
Boolean
- 要素がドキュメントの末尾にあるかどうか。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isLeftToRight()
merge()
要素を同じタイプの前の兄弟とマージします。
同じ ElementType
の要素のみをマージできます。現在の要素に含まれるすべての子要素は、前の兄弟要素に移動されます。
現在の要素がドキュメントから削除されます。
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. var par1 = body.appendParagraph('Paragraph 1.'); var par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge(); // Example 2: Merge table cells // Create a two-dimensional array containing the table's cell contents. var cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'] ]; // Build a table from the array. var table = body.appendTable(cells); // Get the first row in the table. var row = table.getRow(0); // Get the two cells in this row. var cell1 = row.getCell(0); var cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. var merged = cell2.merge();
復路
Paragraph
- 結合された要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeChild(child)
removeFromParent()
親から要素を削除します。
var body = DocumentApp.getActiveDocument().getBody(); // Remove all images in the document body. var imgs = body.getImages(); for (var i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
復路
Paragraph
- 削除された要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removePositionedImage(id)
イメージの ID で PositionedImage
を削除します。
パラメータ
Name | 型 | 説明 |
---|---|---|
id | String | 画像 ID |
復路
Boolean
- 指定した画像が削除されたかどうかを示します。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
正規表現を使用して、指定されたテキスト パターンのすべての置換を特定の置換文字列に置き換えます。
検索パターンは JavaScript 正規表現オブジェクトではなく文字列として渡されます。 このため、パターン内のすべてのバックスラッシュをエスケープする必要があります。
このメソッドは、Google の RE2 正規表現ライブラリを使用します。このライブラリは、サポートされる構文を制限します。
指定された正規表現パターンは、現在の要素に含まれるテキスト ブロックごとに独立して照合されます。
var body = DocumentApp.getActiveDocument().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText("^.*Apps ?Script.*$", "Apps Script");
パラメータ
Name | 型 | 説明 |
---|---|---|
searchPattern | String | 検索する正規表現パターン |
replacement | String | 置換として使用するテキスト |
復路
Element
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAlignment(alignment)
HorizontalAlignment
を設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
alignment | HorizontalAlignment | 水平方向の配置 |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
要素の属性を設定します。
指定する属性パラメータは、各プロパティ名が DocumentApp.Attribute
列挙型内のアイテムであり、各プロパティ値が適用する新しい値であるオブジェクトである必要があります。
var body = DocumentApp.getActiveDocument().getBody(); // Define a custom paragraph style. var style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. var par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
パラメータ
Name | 型 | 説明 |
---|---|---|
attributes | Object | 要素の属性。 |
復路
Paragraph
- 現在の要素。
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeading(heading)
ParagraphHeading
を設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
heading | ParagraphHeading | 見出し |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentEnd(indentEnd)
末尾のインデントをポイント単位で設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
indentEnd | Number | 最後のインデント(ポイント) |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentFirstLine(indentFirstLine)
最初の行のインデントをポイントで設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
indentFirstLine | Number | 先頭行のインデント(ポイント) |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentStart(indentStart)
開始インデントをポイント単位で設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
indentStart | Number | 開始インデント(ポイント) |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLeftToRight(leftToRight)
左から右への設定を行います。
パラメータ
Name | 型 | 説明 |
---|---|---|
leftToRight | Boolean | 左から右に設定 |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLineSpacing(multiplier)
行間隔を、間隔に使用する行数を示す数量として設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
multiplier | Number | 行数 |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(url)
リンク URL を設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
url | String | リンク URL |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setSpacingAfter(spacingAfter)
要素の後のスペースをポイントで設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
spacingAfter | Number | 要素の後のスペース(ポイント単位) |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setSpacingBefore(spacingBefore)
要素の前のスペースをポイントで設定します。
パラメータ
Name | 型 | 説明 |
---|---|---|
spacingBefore | Number | 要素の前のスペース(ポイント単位) |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setText(text)
setTextAlignment(textAlignment)
テキストの配置を設定します。配置に使用できるタイプは DocumentApp.TextAlignment.NORMAL
、DocumentApp.TextAlignment.SUBSCRIPT
、DocumentApp.TextAlignment.SUPERSCRIPT
です。
// Make the entire first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
パラメータ
Name | 型 | 説明 |
---|---|---|
textAlignment | TextAlignment | 適用するテキストの配置タイプ |
復路
Paragraph
- 現在の要素
認証
この方法を使用するスクリプトには、次の 1 つ以上のスコープで承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents