Class TableCell

TableCell

テーブルセルを表す要素。TableCell は常に TableRow 内に含まれ、ListItemParagraphTable のいずれかを含むことができます。ドキュメント構造の詳細については、Google ドキュメントの拡張ガイドをご覧ください。

Methods

方法戻り値の型概要
appendHorizontalRule()HorizontalRule新しい HorizontalRule を作成して追加します。
appendImage(image)InlineImage指定された画像 blob から新しい InlineImage を作成して追加します。
appendImage(image)InlineImage指定された InlineImage を追加します。
appendListItem(listItem)ListItem指定された ListItem を追加します。
appendListItem(text)ListItem新しい ListItem を作成して追加します。
appendParagraph(paragraph)Paragraph指定された Paragraph を追加します。
appendParagraph(text)Paragraph新しい Paragraph を作成して追加します。
appendTable()Table新しい Table を作成して追加します。
appendTable(cells)Table指定されたセルを含む新しい Table を追加します。
appendTable(table)Table指定された Table を追加します。
clear()TableCell要素のコンテンツをクリアします。
copy()TableCell現在の要素から分離されたディープコピーを返します。
editAsText()Text編集用に現在の要素の Text バージョンを取得します。
findElement(elementType)RangeElement要素のコンテンツを指定して、指定された型の子孫を検索します。
findElement(elementType, from)RangeElement要素の内容を検索し、指定された RangeElement から始まる、指定されたタイプの子孫を検索します。
findText(searchPattern)RangeElement正規表現を使用して、要素の内容について、指定されたテキスト パターンを検索します。
findText(searchPattern, from)RangeElement特定のコンテンツ要素から、指定したテキスト パターンで要素のコンテンツを検索します。
getAttributes()Object要素の属性を取得します。
getBackgroundColor()String背景色を取得します。
getChild(childIndex)Element指定した子インデックスにある子要素を取得します。
getChildIndex(child)Integer指定した子要素の子インデックスを取得します。
getColSpan()Integer列スパン(このセルがまたがっているテーブルセルの列の数)を取得します。
getLinkUrl()Stringリンクの URL を取得します。
getNextSibling()Element要素の次の兄弟要素を取得します。
getNumChildren()Integer子の数を取得します。
getPaddingBottom()Number下部のパディングをポイント数で取得します。
getPaddingLeft()Number左側のパディングをポイント数で取得します。
getPaddingRight()Number右のパディングをポイント数で取得します。
getPaddingTop()Number上パディングをポイント数で取得します。
getParent()ContainerElement要素の親要素を取得します。
getParentRow()TableRow現在の TableCell を含む TableRow を取得します。
getParentTable()Table現在の TableCell を含む Table を取得します。
getPreviousSibling()Element要素の前の兄弟要素を取得します。
getRowSpan()Integer行スパンを取得します。これは、このセルがまたがっているテーブルセルの行数です。
getText()String要素のコンテンツをテキスト文字列として取得します。
getTextAlignment()TextAlignmentテキストの配置を取得します。
getType()ElementType要素の ElementType を取得します。
getVerticalAlignment()VerticalAlignmentVerticalAlignment を取得します。
getWidth()Numberセルを含む列の幅をポイント数で取得します。
insertHorizontalRule(childIndex)HorizontalRule指定されたインデックスに新しい HorizontalRule を作成して挿入します。
insertImage(childIndex, image)InlineImage指定された画像 blob から、指定されたインデックスで InlineImage を作成して挿入します。
insertImage(childIndex, image)InlineImage指定された InlineImage を指定されたインデックスに挿入します。
insertListItem(childIndex, listItem)ListItem指定された ListItem を指定されたインデックスに挿入します。
insertListItem(childIndex, text)ListItem指定されたインデックスに新しい ListItem を作成して挿入します。
insertParagraph(childIndex, paragraph)Paragraph指定された Paragraph を指定されたインデックスに挿入します。
insertParagraph(childIndex, text)Paragraph指定されたインデックスに新しい Paragraph を作成して挿入します。
insertTable(childIndex)Table指定されたインデックスに新しい Table を作成して挿入します。
insertTable(childIndex, cells)Table指定されたセルに、指定されたインデックスを持つ新しい Table を作成して挿入します。
insertTable(childIndex, table)Table指定された Table を指定されたインデックスに挿入します。
isAtDocumentEnd()Boolean要素が Document の末尾にあるかどうかを判断します。
merge()TableCell同じタイプの先行する兄弟要素と要素を結合します。
removeChild(child)TableCell指定した子要素を削除します。
removeFromParent()TableCell親から要素を削除します。
replaceText(searchPattern, replacement)Element正規表現を使用して、特定のテキスト パターンをすべて特定の置換文字列に置き換えます。
setAttributes(attributes)TableCell要素の属性を設定します。
setBackgroundColor(color)TableCell背景色を設定します。
setLinkUrl(url)TableCellリンクの URL を設定します。
setPaddingBottom(paddingBottom)TableCell下部のパディングをポイント数で設定します。
setPaddingLeft(paddingLeft)TableCell左側のパディングをポイント単位で設定します。
setPaddingRight(paddingTop)TableCell右のパディングをポイント数で設定します。
setPaddingTop(paddingTop)TableCell上パディングをポイント単位で設定します。
setText(text)TableCellコンテンツを書式なしテキストとして設定します。
setTextAlignment(textAlignment)TableCellテキストの配置を設定します。
setVerticalAlignment(alignment)TableCell垂直方向の配置を設定します。
setWidth(width)TableCell現在のセルを含む列の幅をポイントで設定します。

詳細なドキュメント

appendHorizontalRule()

新しい HorizontalRule を作成して追加します。

HorizontalRule は新しい Paragraph に含まれます。

戻る

HorizontalRule - 新しい水平ルール。

認可

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

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

appendImage(image)

指定された画像 blob から新しい InlineImage を作成して追記します。

InlineImage は新しい Paragraph に含まれます。

パラメータ

名前説明
imageBlobSource画像データ

戻る

InlineImage - 新しいイメージ

認可

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

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

appendImage(image)

指定された InlineImage を追加します。

InlineImage は新しい Paragraph に含まれます。

パラメータ

名前説明
imageInlineImage画像データ

戻る

InlineImage - 追加された画像

認可

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

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

appendListItem(listItem)

指定された ListItem を追加します。

パラメータ

名前説明
listItemListItem追加するリストアイテム

戻る

ListItem - 追加されたリストアイテム

認可

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

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

appendListItem(text)

新しい ListItem を作成して追加します。

パラメータ

名前説明
textStringテキスト コンテンツ

戻る

ListItem - 新しいリストアイテム。

認可

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

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

appendParagraph(paragraph)

指定された Paragraph を追加します。

パラメータ

名前説明
paragraphParagraph追加する段落

戻る

Paragraph - 段落を追加

認可

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

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

appendParagraph(text)

新しい Paragraph を作成して追加します。

パラメータ

名前説明
textStringテキスト コンテンツ

戻る

Paragraph - 新しい段落を作成

認可

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

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

appendTable()

新しい Table を作成して追加します。

戻る

Table - 新しいテーブル。

認可

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

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

appendTable(cells)

指定されたセルを含む新しい Table を追加します。

パラメータ

名前説明
cellsString[][]新しいテーブルに追加するテーブルセルのテキスト コンテンツ

戻る

Table - 追加されたテーブル。

認可

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

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

appendTable(table)

指定された Table を追加します。

パラメータ

名前説明
tableTable追加するテーブル

戻る

Table - 追加されたテーブル。

認可

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

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

clear()

要素のコンテンツをクリアします。

戻る

TableCell - 現在の要素。


copy()

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

その要素内のすべての子要素もコピーされます。新しい要素には親がありません。

戻る

TableCell - 新しいコピー。

認可

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

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

editAsText()

編集用に現在の要素の Text バージョンを取得します。

editAsText を使用して、要素のコンテンツをリッチテキストとして操作します。editAsText モードでは、テキスト以外の要素(InlineImageHorizontalRule など)は無視されます。

削除されたテキスト範囲に完全に含まれる子要素は、その要素から削除されます。

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)

要素のコンテンツを指定して、指定された型の子孫を検索します。

パラメータ

名前説明
elementTypeElementType検索する要素のタイプ

戻る

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;
  }
}

パラメータ

名前説明
elementTypeElementType検索する要素のタイプ
fromRangeElement検索元の検索結果

戻る

RangeElement - 検索要素の次の位置を示す検索結果

認可

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

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

findText(searchPattern)

正規表現を使用して、要素の内容について、指定されたテキスト パターンを検索します。

キャプチャ グループやモード修飾子など、JavaScript の正規表現機能の一部はサポートされていません。

指定された正規表現パターンは、現在の要素に含まれるテキスト ブロックごとに独立して照合されます。

パラメータ

名前説明
searchPatternString検索するパターン

戻る

RangeElement - 検索テキストの位置を示す検索結果。一致がない場合は null を返します。

認可

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

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

findText(searchPattern, from)

特定のコンテンツ要素から、指定したテキスト パターンで要素のコンテンツを検索します。

キャプチャ グループやモード修飾子など、JavaScript の正規表現機能の一部はサポートされていません。

指定された正規表現パターンは、現在の要素に含まれるテキスト ブロックごとに独立して照合されます。

パラメータ

名前説明
searchPatternString検索するパターン
fromRangeElement検索元の検索結果

戻る

RangeElement - 検索テキストの次の位置を示す検索結果。一致がない場合は null を返します。

認可

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

getBackgroundColor()

背景色を取得します。

戻る

String - 背景色。CSS 表記形式('#ffffff' など)で指定します。

認可

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

パラメータ

名前説明
childIndexInteger取得する子要素のインデックス

戻る

Element - 指定されたインデックスの子要素

認可

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

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

getChildIndex(child)

指定した子要素の子インデックスを取得します。

パラメータ

名前説明
childElementインデックスを取得する子要素

戻る

Integer - 子インデックス。

認可

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

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

getColSpan()

列スパン(このセルがまたがっているテーブルセルの列の数)を取得します。マージしていないセルの期間は、1:

戻る

Integer - 列スパンまたは別のセルによって結合されるセルの場合は 0

認可

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

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

getLinkUrl()

リンクの URL を取得します。

戻る

String - リンク URL。この属性に複数の値が含まれている場合は要素に null を指定します。

認可

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

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

getPaddingBottom()

下部のパディングをポイント数で取得します。

戻る

Number - 下部のパディング(ポイント単位)

認可

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

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

getPaddingLeft()

左側のパディングをポイント数で取得します。

戻る

Number - 左パディング、ポイント

認可

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

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

getPaddingRight()

右のパディングをポイント数で取得します。

戻る

Number - 右のパディング(ポイント単位)

認可

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

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

getPaddingTop()

上パディングをポイント数で取得します。

戻る

Number - 上パディング(ポイント単位)

認可

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

getParentRow()

現在の TableCell を含む TableRow を取得します。

戻る

TableRow - 現在のセルを含むテーブル行

認可

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

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

getParentTable()

現在の TableCell を含む Table を取得します。

戻る

Table - 現在のセルを含むテーブル

認可

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

getRowSpan()

行スパンを取得します。これは、このセルがまたがっているテーブルセルの行数です。マージされていないセルの行スパンは 1 です。

戻る

Integer - 行スパンまたは 0(別のセルによってマージされるセル)

認可

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

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

getText()

要素のコンテンツをテキスト文字列として取得します。

戻る

String - テキストの内容としての要素の内容

認可

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

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

getTextAlignment()

テキストの配置を取得します。使用可能なアライメントの種類は、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.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

getVerticalAlignment()

VerticalAlignment を取得します。

戻る

VerticalAlignment - 垂直方向の配置

認可

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

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

getWidth()

セルを含む列の幅をポイント数で取得します。

戻る

Number - 列の幅(ポイント数)

認可

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

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

insertHorizontalRule(childIndex)

指定されたインデックスに新しい HorizontalRule を作成して挿入します。

水平方向のルールは新しい Paragraph に追加されます。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス

戻る

HorizontalRule - 新しい水平ルール。

認可

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

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

insertImage(childIndex, image)

指定された画像 blob から、指定されたインデックスで InlineImage を作成して挿入します。

画像は新しい Paragraph に格納されます。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
imageBlobSource画像データ

戻る

InlineImage - 挿入されたインライン画像

認可

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

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

insertImage(childIndex, image)

指定された InlineImage に、指定されたインデックスを挿入します。

画像は新しい Paragraph に格納されます。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
imageInlineImage挿入する画像

戻る

InlineImage - 挿入されたインライン画像

認可

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

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

insertListItem(childIndex, listItem)

指定された ListItem を指定されたインデックスに挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
listItemListItem挿入するリストアイテム

戻る

ListItem - 新しいリストアイテムを挿入しました

認可

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

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

insertListItem(childIndex, text)

指定されたインデックスに新しい ListItem を作成して挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
textStringテキスト コンテンツ

戻る

ListItem - 新しいリストアイテム。

認可

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

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

insertParagraph(childIndex, paragraph)

指定された Paragraph を指定されたインデックスに挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
paragraphParagraph挿入する段落

戻る

Paragraph - 挿入された段落

認可

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

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

insertParagraph(childIndex, text)

指定されたインデックスに新しい Paragraph を作成して挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
textStringテキスト コンテンツ

戻る

Paragraph - 新しい段落を作成

認可

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

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

insertTable(childIndex)

指定されたインデックスに新しい Table を作成して挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス

戻る

Table - 新しいテーブル。

認可

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

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

insertTable(childIndex, cells)

指定されたセルに、指定されたインデックスを持つ新しい Table を作成して挿入します。

パラメータ

名前説明
childIndexInteger挿入するインデックス
cellsString[][]新しいテーブルに追加するテーブルセルのテキスト コンテンツ

戻る

Table - 新しいテーブル。

認可

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

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

insertTable(childIndex, table)

指定された Table を指定されたインデックスに挿入します。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
tableTable挿入するテーブル

戻る

Table - 挿入されたテーブル

認可

このメソッドを使用するスクリプトには、次の 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 の要素のみです。現在の要素に含まれている子要素は、前の兄弟要素に移動されます。

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

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

戻る

TableCell - マージされた要素。

認可

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

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

removeChild(child)

指定した子要素を削除します。

パラメータ

名前説明
childElement削除する子要素

戻る

TableCell - 現在の要素。

認可

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

戻る

TableCell - 削除された要素。

認可

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

パラメータ

名前説明
searchPatternString検索する正規表現パターン
replacementString置換として使用するテキスト

戻る

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

パラメータ

名前説明
attributesObject要素の属性。

戻る

TableCell - 現在の要素。

認可

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

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

setBackgroundColor(color)

背景色を設定します。

パラメータ

名前説明
colorString背景色(CSS 表記形式、'#ffffff' など)。

戻る

TableCell - 現在の要素。

認可

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

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

setLinkUrl(url)

リンクの URL を設定します。

パラメータ

名前説明
urlStringリンクの URL

戻る

TableCell - 現在の要素。

認可

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

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

setPaddingBottom(paddingBottom)

下部のパディングをポイント数で設定します。

パラメータ

名前説明
paddingBottomNumber下部のパディング(ポイント数)

戻る

TableCell - 現在の要素。

認可

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

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

setPaddingLeft(paddingLeft)

左側のパディングをポイント単位で設定します。

パラメータ

名前説明
paddingLeftNumber左パディング(ポイント数)

戻る

TableCell - 現在の要素。

認可

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

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

setPaddingRight(paddingTop)

右のパディングをポイント数で設定します。

パラメータ

名前説明
paddingTopNumber右パディング(ポイント単位)

戻る

TableCell - 現在の要素。

認可

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

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

setPaddingTop(paddingTop)

上パディングをポイント単位で設定します。

パラメータ

名前説明
paddingTopNumber上パディング(ポイント単位)

戻る

TableCell - 現在の要素。

認可

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

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

setText(text)

コンテンツを書式なしテキストとして設定します。

注: 既存のコンテンツは消去されます。

パラメータ

名前説明
textString新しいテキスト コンテンツ

戻る

TableCell - 現在の要素。

認可

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

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

setTextAlignment(textAlignment)

テキストの配置を設定します。使用可能なアライメントのタイプは、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT です。

// Make the entire first paragraph be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

パラメータ

名前説明
textAlignmentTextAlignment適用するテキストの配置タイプ

戻る

TableCell - 現在の要素。

認可

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

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

setVerticalAlignment(alignment)

垂直方向の配置を設定します。

パラメータ

名前説明
alignmentVerticalAlignment垂直方向の配置

戻る

TableCell - 現在の要素。

認可

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

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

setWidth(width)

現在のセルを含む列の幅をポイントで設定します。

パラメータ

名前説明
widthNumber列の幅(ポイント数)

戻る

TableCell - 現在の要素。

認可

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

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