汎用要素。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()
現在の要素を Date
として返します。
要素が Date
であることがわかっている場合は、このメソッドを使用して、タイプを Date
として設定します。これにより、Apps Script エディタのオートコンプリートで、Date
で使用できるメソッドが表示されるようになります。
戻る
Date
- タイプが Date
に設定されている現在の要素。
認可
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
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
列挙型のアイテムに対応する、有効な要素属性のプロパティを含むオブジェクトになります。
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