汎用要素。Document の内容は要素として表されます。たとえば、ListItem、Paragraph、Table は要素であり、getType() など、Element で定義されたすべてのメソッドを継承します。
実装クラス
| 名前 | 概要 |
|---|---|
Body | Google ドキュメントのタブの内容。 |
Container | 他の要素を含むことができる汎用要素。 |
Date | 書式設定された日付を表す要素 |
Equation | 数式を表す要素。 |
Equation | 数学の Equation の関数を表す要素。 |
Equation | 数学の Equation の関数区切り文字を表す要素。 |
Equation | 数学の Equation の記号を表す要素。 |
Footer | フッター セクションを表す要素。 |
Footnote | 脚注を表す要素。 |
Footnote | 脚注セクションを表す要素。 |
Header | ヘッダー セクションを表す要素。 |
Horizontal | 水平ルールを表す要素。 |
Inline | 埋め込み図形描画を表す要素。 |
Inline | 埋め込み画像を表す要素。 |
List | リスト項目を表す要素。 |
Page | 改ページを表す要素。 |
Paragraph | 段落を表す要素。 |
Person | 人物へのリンクを表す要素。 |
Rich | Google リソース(ドライブ ファイルや YouTube 動画など)へのリンクを表す要素。 |
Table | テーブルを表す要素。 |
Table | テーブルセルを表す要素。 |
Table | 目次を含む要素。 |
Table | テーブル行を表す要素。 |
Text | リッチテキスト領域を表す要素。 |
Unsupported | ページ番号など、不明な領域やスクリプトの影響を受けない領域を表す要素。 |
メソッド
詳細なドキュメント
asBody()
asDate()
asEquation()
asEquationFunction()
現在の要素を EquationFunction として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
EquationFunction - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asEquationFunctionArgumentSeparator()
現在の要素を EquationFunctionArgumentSeparator として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
EquationFunctionArgumentSeparator - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asEquationSymbol()
現在の要素を EquationSymbol として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
EquationSymbol - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asFootnote()
asFootnoteSection()
現在の要素を FootnoteSection として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
FootnoteSection - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asHeaderSection()
現在の要素を HeaderSection として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
HeaderSection - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asHorizontalRule()
現在の要素を HorizontalRule として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
HorizontalRule - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asInlineDrawing()
現在の要素を InlineDrawing として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
InlineDrawing - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asInlineImage()
現在の要素を InlineImage として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
InlineImage - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asListItem()
asPageBreak()
asParagraph()
asPerson()
現在の要素を Person として返します。
要素が Person であることがわかっている場合は、このメソッドを使用してそのタイプを人物として設定します。これにより、Apps Script エディタの予測入力で、人物要素で使用できるメソッドが表示されます。
戻る
Person - タイプが Person に設定された現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asRichLink()
現在の要素を RichLink として返します(Google スプレッドシート ファイルへのリンクなど)。
要素が RichLink であることがわかっている場合は、このメソッドを使用してその型を RichLink として設定します。これにより、Apps Script エディタの予測入力で、RichLink で使用できるメソッドが表示されます。
戻る
RichLink - タイプが RichLink に設定された現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asTable()
asTableCell()
asTableOfContents()
現在の要素を TableOfContents として返します。
このメソッドは、特定の型の要素であることがわかっている場合に、オートコンプリートを補助するために使用します。
戻る
TableOfContents - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
asTableRow()
asText()
copy()
getAttributes()
要素の属性を取得します。
結果は、有効な要素属性ごとにプロパティを含むオブジェクトです。各プロパティ名は DocumentApp.Attribute 列挙型の項目に対応します。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
戻る
Object - 要素の属性。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNextSibling()
getParent()
要素の親要素を取得します。
親要素に現在の要素が含まれている。
戻る
ContainerElement|null - 親要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getPreviousSibling()
getType()
要素の ElementType を取得します。
getType() を使用して、指定された要素の正確な型を特定します。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const 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
isAtDocumentEnd()
merge()
要素を同じタイプの前の兄弟要素とマージします。
統合できるのは、同じ ElementType の要素のみです。現在の要素に含まれる子要素は、前の兄弟要素に移動されます。
現在の要素がドキュメントから削除されます。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document's active tab. const par1 = body.appendParagraph('Paragraph 1.'); const 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. const cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'], ]; // Build a table from the array. const table = body.appendTable(cells); // Get the first row in the table. const row = table.getRow(0); // Get the two cells in this row. const cell1 = row.getCell(0); const cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. const merged = cell2.merge();
戻る
Element|null - マージされた要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
removeFromParent()
要素を親から削除します。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
戻る
Element|null - 削除された要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setAttributes(attributes)
要素の属性を設定します。
指定された attributes パラメータは、各プロパティ名が DocumentApp.Attribute 列挙型のアイテムで、各プロパティ値が適用される新しい値であるオブジェクトである必要があります。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const 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. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
attributes | Object | 要素の属性。 |
戻る
Element - 現在の要素。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents