Interface Element

要素

汎用要素。Document 個のコンテンツ 要素として表されます。たとえば、ListItemParagraphTable は次のようになります。 要素であり、Element で定義されたすべてのメソッド(getType() など)を継承します。

クラスの実装

名前概要
BodyGoogle ドキュメント内のドキュメントのタブのコンテンツ。
ContainerElement他の要素を含む可能性のある汎用要素。
Date書式設定された日付を表す要素
Equation数式を表す要素。
EquationFunction数学的 Equation で関数を表す要素。
EquationFunctionArgumentSeparator数学的 Equation で関数セパレータを表す要素。
EquationSymbol数学的 Equation で記号を表す要素。
FooterSectionフッター セクションを表す要素。
Footnote脚注を表す要素。
FootnoteSection脚注セクションを表す要素。
HeaderSectionヘッダー セクションを表す要素。
HorizontalRule水平ルールを表す要素。
InlineDrawing埋め込まれた図形描画を表す要素。
InlineImage埋め込み画像を表す要素。
ListItemリストアイテムを表す要素。
PageBreak改ページを表す要素。
Paragraph段落を表す要素。
Person人物へのリンクを表す要素。
RichLinkドライブ ファイルや YouTube 動画などの Google リソースへのリンクを表す要素。
Tableテーブルを表す要素。
TableCell表のセルを表す要素。
TableOfContents目次を含む要素。
TableRow表の行を表す要素。
Textリッチテキスト領域を表す要素。
UnsupportedElement不明な領域、またはスクリプトの影響を受けない領域を表す要素。 表示されます。

メソッド

メソッド戻り値の型概要
asBody()Body現在の要素を Body として返します。
asDate()Date現在の要素を Date として返します。
asEquation()Equation現在の要素を Equation として返します。
asEquationFunction()EquationFunction現在の要素を EquationFunction として返します。
asEquationFunctionArgumentSeparator()EquationFunctionArgumentSeparator現在の要素を EquationFunctionArgumentSeparator として返します。
asEquationSymbol()EquationSymbol現在の要素を EquationSymbol として返します。
asFooterSection()FooterSection現在の要素を FooterSection として返します。
asFootnote()Footnote現在の要素を Footnote として返します。
asFootnoteSection()FootnoteSection現在の要素を FootnoteSection として返します。
asHeaderSection()HeaderSection現在の要素を HeaderSection として返します。
asHorizontalRule()HorizontalRule現在の要素を HorizontalRule として返します。
asInlineDrawing()InlineDrawing現在の要素を InlineDrawing として返します。
asInlineImage()InlineImage現在の要素を InlineImage として返します。
asListItem()ListItem現在の要素を ListItem として返します。
asPageBreak()PageBreak現在の要素を PageBreak として返します。
asParagraph()Paragraph現在の要素を Paragraph として返します。
asPerson()Person現在の要素を Person として返します。
asRichLink()RichLink現在の要素を RichLink として返します(Google スプレッドシート ファイルへのリンクなど)。
asTable()Table現在の要素を Table として返します。
asTableCell()TableCell現在の要素を TableCell として返します。
asTableOfContents()TableOfContents現在の要素を TableOfContents として返します。
asTableRow()TableRow現在の要素を TableRow として返します。
asText()Text現在の要素を Text として返します。
copy()Element現在の要素の分離されたディープコピーを返します。
getAttributes()Object要素の属性を取得します。
getNextSibling()Element要素の次の兄弟要素を取得します。
getParent()ContainerElement要素の親要素を取得します。
getPreviousSibling()Element要素の前の兄弟要素を取得します。
getType()ElementType要素の ElementType を取得します。
isAtDocumentEnd()Boolean要素が Document の最後にあるかどうかを決定します。
merge()Element要素を、先行する同じ型の兄弟要素と結合します。
removeFromParent()Element要素を親から削除します。
setAttributes(attributes)Element要素の属性を設定します。

詳細なドキュメント

asBody()

現在の要素を Body として返します。

特定の要素が特定の要素であることが判明している場合に、予測入力の際にこの方法を使用できます。 あります。

戻る

Body - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asDate()

現在の要素を Date として返します。

要素が Date であることがわかっている場合は、このメソッドを使用して型を Date に設定します。これにより、Apps Script エディタの予測入力に、使用できるメソッドが表示されます。 Date に置き換えます。

戻る

Date - タイプが Date に設定された現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asEquation()

現在の要素を Equation として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

Equation - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

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

asFooterSection()

現在の要素を FooterSection として返します。

特定の要素が特定の要素であることが判明している場合に、予測入力の際にこの方法を使用できます。 あります。

戻る

FooterSection - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asFootnote()

現在の要素を Footnote として返します。

特定の要素が特定の要素であることが判明している場合に、予測入力の際にこの方法を使用できます。 あります。

戻る

Footnote - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

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()

現在の要素を ListItem として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

ListItem - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPageBreak()

現在の要素を PageBreak として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

PageBreak - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asParagraph()

現在の要素を Paragraph として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

Paragraph - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asPerson()

現在の要素を Person として返します。

要素が Person であることがわかっている場合は、このメソッドを使用してタイプを人物として設定します。 これにより、Apps Script エディタの予測入力で、 必要があります。

戻る

Person - タイプが Person に設定された現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

現在の要素を RichLink として返します(Google スプレッドシート ファイルへのリンクなど)。

要素が RichLink であることがわかっている場合は、このメソッドを使用して型を RichLink に設定します。これにより、Apps Script エディタの予測入力に、実行可能なメソッドが表示されます。 RichLink とともに使用します。

戻る

RichLink - タイプが RichLink に設定された現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTable()

現在の要素を Table として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

Table - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableCell()

現在の要素を TableCell として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

TableCell - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableOfContents()

現在の要素を TableOfContents として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

TableOfContents - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asTableRow()

現在の要素を TableRow として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

TableRow - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

asText()

現在の要素を Text として返します。

特定の要素が特定の要素であることが判明している場合に、この方法で予測入力を補完できます。 あります。

戻る

Text - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

copy()

現在の要素の分離されたディープコピーを返します。

その要素に含まれている子要素もすべてコピーされます。新しい要素には できます。

戻る

Element - 新しいコピー。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

要素の属性を取得します。

その結果は、各有効な要素属性のプロパティを含むオブジェクトとなり、 プロパティ名は、DocumentApp.Attribute 列挙型の項目に対応しています。

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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()

要素の次の兄弟要素を取得します。

次の兄弟要素は同じ親を持ち、現在の要素に従います。

戻る

Element - 次の兄弟要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 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

getPreviousSibling()

要素の前の兄弟要素を取得します。

前の兄弟要素は、同じ親を持ち、現在の要素の前に配置されます。

戻る

Element - 前の兄弟要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

要素の ElementType を取得します。

getType() を使用して、指定された要素の正確な型を特定します。

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Obtain the first element in the active tab's 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()

要素が Document の最後にあるかどうかを決定します。

戻る

Boolean - 要素がタブの最後にあるかどうか。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

merge()

要素を、先行する同じ型の兄弟要素と結合します。

結合できるのは同じ ElementType の要素のみです。Deployment に含まれる子要素は、 現在の要素は前の兄弟要素に移動されます。

現在の要素がドキュメントから削除されます。

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.getBody();

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
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 doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab()
var body = documentTab.getBody();

// Remove all images in the active tab's 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 doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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);

パラメータ

名前説明
attributesObject要素の属性。

戻る

Element - 現在の要素。

承認

このメソッドを使用するスクリプトには、次のスコープの 1 つ以上を使用した承認が必要です。

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents