Class ListItem

ListItem

リスト項目を表す要素。ListItem は、リスト ID に関連付けられた Paragraph です。ListItem には、EquationFootnoteHorizontalRuleInlineDrawingInlineImagePageBreakText の各要素を含めることができます。ドキュメント構造の詳細については、Google ドキュメントを拡張するためのガイドをご覧ください。

ListItems に改行文字を含めることはできません。改行文字(\n)は改行文字(\r)に変換されます。

同じリスト ID を持つ ListItems は同じリストに属し、それに応じて番号が付けられます。特定のリストの ListItems は、タブ内で隣接している必要も、同じ親要素を持つ必要もありません。次の例に示すように、同じリストに属する 2 つの項目は、連続した番号付けを維持しながら、タブ内の任意の場所に存在できます。

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Append a new list item to the body.
const item1 = body.appendListItem('Item 1');

// Log the new list item's list ID.
Logger.log(item1.getListId());

// Append a table after the list item.
body.appendTable([['Cell 1', 'Cell 2']]);

// Append a second list item with the same list ID. The two items are treated as
// the same list, despite not being consecutive.
const item2 = body.appendListItem('Item 2');
item2.setListId(item1);

メソッド

メソッド戻り値の型概要
addPositionedImage(image)PositionedImage指定された画像 BLOB から新しい PositionedImage を作成して挿入します。
appendHorizontalRule()HorizontalRule新しい HorizontalRule を作成して追加します。
appendInlineImage(image)InlineImage指定されたイメージ blob から新しい InlineImage を作成して追加します。
appendInlineImage(image)InlineImage指定された InlineImage を追加します。
appendPageBreak()PageBreak新しい PageBreak を作成して追加します。
appendPageBreak(pageBreak)PageBreak指定された PageBreak を追加します。
appendText(text)Text指定された内容で新しい Text 要素を作成して追加します。
appendText(text)Text指定された Text 要素を追加します。
clear()ListItem要素の内容をクリアします。
copy()ListItem現在の要素の切り離されたディープコピーを返します。
editAsText()Text編集用に、現在の要素の Text バージョンを取得します。
findElement(elementType)RangeElement|null要素のコンテンツで、指定されたタイプの子孫を検索します。
findElement(elementType, from)RangeElement|null指定された RangeElement から開始して、要素の内容から指定された型の子孫を検索します。
findText(searchPattern)RangeElement|null正規表現を使用して、要素のコンテンツで指定されたテキスト パターンを検索します。
findText(searchPattern, from)RangeElement|null指定された検索結果から開始して、要素の内容で指定されたテキスト パターンを検索します。
getAlignment()HorizontalAlignment|nullHorizontalAlignment を取得します。
getAttributes()Object要素の属性を取得します。
getChild(childIndex)Element指定された子インデックスにある子要素を取得します。
getChildIndex(child)Integer指定された子要素の子インデックスを取得します。
getGlyphType()GlyphType|nullリストアイテムの GlyphType を取得します。
getHeading()ParagraphHeading|nullParagraphHeading を取得します。
getIndentEnd()Number|null終了インデントをポイント単位で取得します。
getIndentFirstLine()Number|null段落の 1 行目のインデントをポイント単位で取得します。
getIndentStart()Number|null開始インデントを取得します。
getLineSpacing()Number|null行間をポイント単位で取得します。
getLinkUrl()String|nullリンクの URL を取得します。
getListId()String|nullリスト ID を取得します。
getNestingLevel()Integerリストアイテムのネストレベルを取得します。
getNextSibling()Element|null要素の次の兄弟要素を取得します。
getNumChildren()Integer子どもの数を取得します。
getParent()ContainerElement|null要素の親要素を取得します。
getPositionedImage(id)PositionedImage画像の ID で PositionedImage を取得します。
getPositionedImages()PositionedImage[]段落にアンカーされているすべての PositionedImage オブジェクトを取得します。
getPreviousSibling()Element|null要素の前の兄弟要素を取得します。
getSpacingAfter()Number|null要素の後のスペースをポイント単位で取得します。
getSpacingBefore()Number|null要素の前の間隔をポイント単位で取得します。
getText()String要素のコンテンツをテキスト文字列として取得します。
getTextAlignment()TextAlignment|nullテキストの配置を取得します。
getType()ElementType要素の ElementType を取得します。
insertHorizontalRule(childIndex)HorizontalRule指定されたインデックスに HorizontalRule を作成して挿入します。
insertInlineImage(childIndex, image)InlineImage指定されたイメージ BLOB から指定されたインデックスに新しい InlineImage を作成して挿入します。
insertInlineImage(childIndex, image)InlineImage指定されたインデックスに指定された InlineImage を挿入します。
insertPageBreak(childIndex)PageBreak指定されたインデックスに新しい PageBreak を作成して挿入します。
insertPageBreak(childIndex, pageBreak)PageBreak指定されたインデックスに指定された PageBreak を挿入します。
insertText(childIndex, text)Text指定されたインデックスに新しいテキスト要素を作成して挿入します。
insertText(childIndex, text)Text指定されたインデックスに、指定されたテキスト コンテンツを含む Text 要素を挿入します。
isAtDocumentEnd()Boolean要素が Document の末尾にあるかどうかを判断します。
isLeftToRight()Boolean|null左から右への設定を取得します。
merge()ListItem|null要素を同じタイプの前の兄弟要素とマージします。
removeChild(child)ListItem指定された子要素を削除します。
removeFromParent()ListItem|null要素を親から削除します。
removePositionedImage(id)Boolean画像の ID で PositionedImage を削除します。
replaceText(searchPattern, replacement)Element正規表現を使用して、指定されたテキスト パターンのすべての出現箇所を、指定された置換文字列に置き換えます。
setAlignment(alignment)ListItemHorizontalAlignment を設定します。
setAttributes(attributes)ListItem要素の属性を設定します。
setGlyphType(glyphType)ListItemリストアイテムの GlyphType を設定します。
setHeading(heading)ListItemParagraphHeading を設定します。
setIndentEnd(indentEnd)ListItem末尾のインデントをポイント単位で設定します。
setIndentFirstLine(indentFirstLine)ListItem先頭行のインデントをポイント単位で設定します。
setIndentStart(indentStart)ListItem開始インデントをポイント単位で設定します。
setLeftToRight(leftToRight)ListItem左から右への設定を行います。
setLineSpacing(multiplier)ListItem行間を、間隔に使用する行数を示す量として設定します。
setLinkUrl(url)ListItemリンクの URL を設定します。
setListId(listItem)ListItemリスト ID を設定します。
setNestingLevel(nestingLevel)ListItemリストアイテムのネストレベルを設定します。
setSpacingAfter(spacingAfter)ListItem要素の後のスペースをポイント単位で設定します。
setSpacingBefore(spacingBefore)ListItem要素の前の間隔をポイント単位で設定します。
setText(text)voidリストアイテムのコンテンツをテキストとして設定します。
setTextAlignment(textAlignment)ListItemテキストの配置を設定します。

詳細なドキュメント

addPositionedImage(image)

指定された画像 BLOB から新しい PositionedImage を作成して挿入します。

パラメータ

名前説明
imageBlobSource画像データ

戻る

PositionedImage - 新しい位置に配置された画像

承認

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

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

appendHorizontalRule()

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

戻る

HorizontalRule - 新しい水平罫線

承認

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

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

appendInlineImage(image)

指定されたイメージ blob から新しい InlineImage を作成して追加します。

パラメータ

名前説明
imageBlobSource画像データ

戻る

InlineImage - 追加された画像

承認

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

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

appendInlineImage(image)

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

パラメータ

名前説明
imageInlineImage画像データ

戻る

InlineImage - 追加された画像

承認

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

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

appendPageBreak()

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

注: PageBreaksTableCells 内に含めることはできません。現在の要素がテーブルセルに含まれている場合、例外がスローされます。

戻る

PageBreak - 新しい改ページ要素

承認

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

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

appendPageBreak(pageBreak)

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

注: PageBreaksTableCells 内に含めることはできません。現在の要素がテーブルセルに含まれている場合、例外がスローされます。

パラメータ

名前説明
pageBreakPageBreak追加する改ページ

戻る

PageBreak - 追加された改ページ要素

承認

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

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

appendText(text)

指定された内容で新しい Text 要素を作成して追加します。

パラメータ

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

戻る

Text - 新しいテキスト要素

承認

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

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

appendText(text)

指定された Text 要素を追加します。

パラメータ

名前説明
textText追加するテキスト要素

戻る

Text - 追加されたテキスト要素

承認

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

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

clear()

要素の内容をクリアします。

戻る

ListItem - 現在の要素。


copy()

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

要素に含まれる子要素もコピーされます。新しい要素には親がありません。

戻る

ListItem - 新しいコピー。

承認

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

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

editAsText()

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

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

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

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().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|null - 検索要素の位置を示す検索結果。

承認

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

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

findElement(elementType, from)

指定された RangeElement から開始して、要素のコンテンツで指定されたタイプの子孫を検索します。

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Define the search parameters.

let searchResult = null;

// Search until the paragraph is found.
while (
    (searchResult = body.findElement(
         DocumentApp.ElementType.PARAGRAPH,
         searchResult,
         ))) {
  const par = searchResult.getElement().asParagraph();
  if (par.getHeading() === DocumentApp.ParagraphHeading.HEADING1) {
    // Found one, update and stop.
    par.setText('This is the first header.');
    break;
  }
}

パラメータ

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

戻る

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

承認

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

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

findText(searchPattern)

正規表現を使用して、要素のコンテンツで指定されたテキスト パターンを検索します。

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

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

パラメータ

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

戻る

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

承認

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

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

findText(searchPattern, from)

指定された検索結果から、要素の内容で指定されたテキスト パターンを検索します。

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

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

パラメータ

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

戻る

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

承認

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

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

getAlignment()

HorizontalAlignment を取得します。

戻る

HorizontalAlignment|null - 配置

承認

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

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

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

getChild(childIndex)

指定された子インデックスにある子要素を取得します。

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Obtain the first element in the tab.
const 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

getGlyphType()

リストアイテムの GlyphType を取得します。

戻る

GlyphType|null - グリフタイプ

承認

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

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

getHeading()

ParagraphHeading を取得します。

戻る

ParagraphHeading|null - 見出し

承認

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

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

getIndentEnd()

終了インデントをポイント単位で取得します。

戻る

Number|null - 終了インデント(ポイント単位)

承認

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

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

getIndentFirstLine()

段落の 1 行目のインデントをポイント単位で取得します。

戻る

Number|null - 先頭行のインデント(ポイント単位)

承認

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

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

getIndentStart()

開始インデントを取得します。

戻る

Number|null - 開始インデント

承認

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

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

getLineSpacing()

行間をポイント単位で取得します。

戻る

Number|null - 行間隔(ポイント単位)

承認

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

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

getLinkUrl()

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

戻る

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

承認

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

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

getListId()

リスト ID を取得します。

戻る

String|null - リスト ID

承認

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

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

getNestingLevel()

リストアイテムのネストレベルを取得します。

デフォルトでは、リストアイテムのネストレベルは 0 です。ネストレベルによって、リスト項目で使用されるグリフが決まります。

戻る

Integer - ネスト レベル

承認

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

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

getNextSibling()

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

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

戻る

Element|null - 次の兄弟要素。

承認

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

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

getNumChildren()

子どもの数を取得します。

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Log the number of elements in the tab.
Logger.log(`There are ${body.getNumChildren()} elements in the tab's body.`);

戻る

Integer - 子の数。

承認

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

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

getParent()

要素の親要素を取得します。

親要素に現在の要素が含まれている。

戻る

ContainerElement|null - 親要素。

承認

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

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

getPositionedImage(id)

画像の ID で PositionedImage を取得します。

パラメータ

名前説明
idString画像 ID

戻る

PositionedImage - 配置された画像

承認

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

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

getPositionedImages()

段落にアンカーされているすべての PositionedImage オブジェクトを取得します。

戻る

PositionedImage[] - 位置指定された画像のリスト

承認

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

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

getPreviousSibling()

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

前の兄弟は同じ親を持ち、現在の要素の前にあります。

戻る

Element|null - 前の兄弟要素。

承認

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

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

getSpacingAfter()

要素の後のスペースをポイント単位で取得します。

戻る

Number|null - 要素の後のスペース(ポイント単位)

承認

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

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

getSpacingBefore()

要素の前の間隔をポイント単位で取得します。

戻る

Number|null - 要素の前の間隔(ポイント単位)

承認

このメソッドを使用するスクリプトには、次の 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 - テキストの配置のタイプ。テキストに複数のタイプのテキストの配置が含まれている場合、またはテキストの配置が設定されていない場合は null

承認

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

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

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

insertHorizontalRule(childIndex)

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

パラメータ

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

戻る

HorizontalRule - 新しい水平罫線要素

承認

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

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

insertInlineImage(childIndex, image)

指定されたイメージ BLOB から指定されたインデックスに新しい InlineImage を作成して挿入します。

パラメータ

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

戻る

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

承認

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

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

insertInlineImage(childIndex, image)

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

パラメータ

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

戻る

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

承認

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

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

insertPageBreak(childIndex)

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

注: PageBreaksTableCells 内に含めることはできません。現在の要素がテーブルセルに含まれている場合、例外がスローされます。

パラメータ

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

戻る

PageBreak - 新しい改ページ要素

承認

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

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

insertPageBreak(childIndex, pageBreak)

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

注: PageBreaksTableCells 内に含めることはできません。現在の要素がテーブルセルに含まれている場合、例外がスローされます。

パラメータ

名前説明
childIndexInteger要素を挿入するインデックス
pageBreakPageBreak挿入する改ページ

戻る

PageBreak - 挿入された改ページ要素

承認

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

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

insertText(childIndex, text)

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

パラメータ

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

戻る

Text - 新しいテキスト要素

承認

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

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

insertText(childIndex, text)

指定されたインデックスに、指定されたテキスト コンテンツを含む Text 要素を挿入します。

パラメータ

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

戻る

Text - 挿入されたテキスト要素

承認

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

isLeftToRight()

左から右への設定を取得します。

戻る

Boolean|null - 左から右への設定

承認

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

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

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

戻る

ListItem|null - マージされた要素。

承認

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

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

removeChild(child)

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

パラメータ

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

戻る

ListItem - 現在の要素

承認

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

戻る

ListItem|null - 削除された要素。

承認

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

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

removePositionedImage(id)

画像の ID で PositionedImage を削除します。

パラメータ

名前説明
idString

戻る

Boolean - 指定された画像が削除されたかどうか

承認

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

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

replaceText(searchPattern, replacement)

正規表現を使用して、指定されたテキスト パターンのすべての出現箇所を、指定された置換文字列に置き換えます。

検索パターンは、JavaScript の正規表現オブジェクトではなく、文字列として渡されます。そのため、パターン内のバックスラッシュはすべてエスケープする必要があります。

このメソッドは、Google の RE2 正規表現ライブラリを使用します。これにより、サポートされる構文が制限されます。

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

const body =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().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

setAlignment(alignment)

HorizontalAlignment を設定します。

パラメータ

名前説明
alignmentHorizontalAlignment水平方向の配置

戻る

ListItem - 現在の要素

承認

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

パラメータ

名前説明
attributesObject要素の属性。

戻る

ListItem - 現在の要素。

承認

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

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

setGlyphType(glyphType)

リストアイテムの GlyphType を設定します。

パラメータ

名前説明
glyphTypeGlyphTypeグリフの種類

戻る

ListItem - 現在の要素

承認

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

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

setHeading(heading)

ParagraphHeading を設定します。

パラメータ

名前説明
headingParagraphHeading見出し

戻る

ListItem - 現在の要素

承認

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

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

setIndentEnd(indentEnd)

末尾のインデントをポイント単位で設定します。

パラメータ

名前説明
indentEndNumber終了インデント(ポイント単位)

戻る

ListItem - 現在の要素

承認

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

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

setIndentFirstLine(indentFirstLine)

先頭行のインデントをポイント単位で設定します。

パラメータ

名前説明
indentFirstLineNumber先頭行のインデント(ポイント単位)

戻る

ListItem - 現在の要素

承認

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

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

setIndentStart(indentStart)

開始インデントをポイント単位で設定します。

パラメータ

名前説明
indentStartNumber開始インデント(ポイント単位)

戻る

ListItem - 現在の要素

承認

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

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

setLeftToRight(leftToRight)

左から右への設定を行います。

パラメータ

名前説明
leftToRightBoolean左から右への設定

戻る

ListItem - 現在の要素

承認

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

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

setLineSpacing(multiplier)

行間を、間隔に使用する行数を示す量として設定します。

パラメータ

名前説明
multiplierNumber行数

戻る

ListItem - 現在の要素

承認

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

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

setLinkUrl(url)

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

パラメータ

名前説明
urlStringリンクの URL

戻る

ListItem - 現在の要素

承認

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

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

setListId(listItem)

リスト ID を設定します。

リスト ID は、指定された ListItem に対して同じ値に設定されます。2 つの ListItems は同じリストのメンバーとして扱われます。

パラメータ

名前説明
listItemListItem使用するリスト ID を持つリストアイテム

戻る

ListItem - 現在の要素

承認

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

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

setNestingLevel(nestingLevel)

リストアイテムのネストレベルを設定します。

デフォルトでは、リストアイテムのネストレベルは 0 です。ネストレベルによって、リスト項目で使用されるグリフが決まります。

パラメータ

名前説明
nestingLevelIntegerネスト レベル

戻る

ListItem - 現在の要素

承認

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

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

setSpacingAfter(spacingAfter)

要素の後のスペースをポイント単位で設定します。

パラメータ

名前説明
spacingAfterNumber要素の後の間隔(ポイント単位)

戻る

ListItem - 現在の要素

承認

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

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

setSpacingBefore(spacingBefore)

要素の前の間隔をポイント単位で設定します。

パラメータ

名前説明
spacingBeforeNumber要素の前の間隔(ポイント単位)

戻る

ListItem - 現在の要素

承認

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

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

setText(text)

リストアイテムのコンテンツをテキストとして設定します。

注: 既存のコンテンツはクリアされます。

パラメータ

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

承認

このメソッドを使用するスクリプトには、次の 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 in the active tab be superscript.
const documentTab =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

パラメータ

名前説明
textAlignmentTextAlignment適用するテキストの配置の種類

戻る

ListItem - 現在の要素

承認

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

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