汎用要素です。Document
のコンテンツは要素として表現されます。たとえば、ListItem
、Paragraph
、Table
は要素であり、Element
で定義されたすべてのメソッド(getType()
など)を継承します。
クラスの実装
名前 | 概要 |
---|---|
Body | ドキュメントの本文を表す要素。 |
ContainerElement | 他の要素を含む可能性のある汎用要素です。 |
Date | 書式設定された日付を表す要素 |
Equation | 数式を表す要素。 |
EquationFunction | 数学的な Equation の関数を表す要素。 |
EquationFunctionArgumentSeparator | 数学的な Equation における関数の区切り文字を表す要素。 |
EquationSymbol | 数学的な Equation の記号を表す要素。 |
FooterSection | フッター セクションを表す要素。 |
Footnote | 脚注を表す要素。 |
FootnoteSection | 脚注セクションを表す要素。 |
HeaderSection | ヘッダー セクションを表す要素。 |
HorizontalRule | 水平方向の規則を表す要素。 |
InlineDrawing | 埋め込み図形描画を表す要素。 |
InlineImage | 埋め込み画像を表す要素。 |
ListItem | リストアイテムを表す要素。 |
PageBreak | 改ページを表す要素。 |
Paragraph | 段落を表す要素。 |
Person | ユーザーへのリンクを表す要素。 |
RichLink | Google リソース(ドライブのファイルや YouTube 動画など)へのリンクを表す要素。 |
Table | テーブルを表す要素。 |
TableCell | テーブルのセルを表す要素。 |
TableOfContents | 目次を含む要素。 |
TableRow | テーブルの行を表す要素。 |
Text | リッチテキスト形式の領域を表す要素。 |
UnsupportedElement | ページ番号など、不明な地域やスクリプトの影響を受けない地域を表す要素。 |
Methods
詳細なドキュメント
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
- 型が 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
列挙型のアイテムに対応しています。
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
getNextSibling()
getParent()
要素の親要素を取得します。
親要素には現在の要素が含まれます。
リターン
ContainerElement
- 親要素。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
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
isAtDocumentEnd()
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();
リターン
Element
- 結合された要素。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
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(); }
リターン
Element
- 削除された要素。
承認
この方法を使用するスクリプトには、次の 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
attributes | Object | 要素の属性。 |
リターン
Element
- 現在の要素。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents