Class Text

テキスト

リッチテキストの領域を表す要素。Document 内のテキストはすべて Text 要素内にあります。Text 要素は EquationEquationFunctionListItemParagraph のいずれかに含めることができ、他の要素を含めることはできません。ドキュメント構造の詳細については、Google ドキュメントの拡張ガイドをご覧ください。

var body = DocumentApp.getActiveDocument().getBody();

// Use editAsText to obtain a single text element containing
// all the characters in the document.
var text = body.editAsText();

// Insert text at the beginning of the document.
text.insertText(0, 'Inserted text.\n');

// Insert text at the end of the document.
text.appendText('\nAppended text.');

// Make the first half of the document blue.
text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');

Methods

メソッド戻り値の型概要
appendText(text)Text指定されたテキストをこのテキスト領域の末尾に追加します。
copy()Text現在の要素から分離されたディープコピーを返します。
deleteText(startOffset, endOffsetInclusive)Textテキストの範囲を削除します。
editAsText()Text編集用に、現在の要素の Text バージョンを取得します。
findText(searchPattern)RangeElement正規表現を使用して、要素のコンテンツ内で、指定されたテキスト パターンを検索します。
findText(searchPattern, from)RangeElement要素の検索結果から、指定した検索結果から始まる指定したテキスト パターンを探します。
getAttributes()Object要素の属性を取得します。
getAttributes(offset)Object指定された文字オフセットにある属性を取得します。
getBackgroundColor()String背景色の設定を取得します。
getBackgroundColor(offset)String指定された文字オフセットの背景色を取得します。
getFontFamily()Stringフォント ファミリーの設定を取得します。
getFontFamily(offset)String指定された文字オフセットでフォント ファミリーを取得します。
getFontSize()Numberフォントサイズの設定を取得します。
getFontSize(offset)Number指定された文字オフセットでのフォントサイズを取得します。
getForegroundColor()String前景色の色設定を取得します。
getForegroundColor(offset)String指定された文字オフセットで前景色を取得します。
getLinkUrl()Stringリンク URL を取得します。
getLinkUrl(offset)String指定された文字オフセットでリンク URL を取得します。
getNextSibling()Element要素の次の兄弟要素を取得します。
getParent()ContainerElement要素の親要素を取得します。
getPreviousSibling()Element要素の前の兄弟要素を取得します。
getText()String要素のコンテンツをテキスト文字列として取得します。
getTextAlignment()TextAlignmentテキストの配置を取得します。
getTextAlignment(offset)TextAlignment1 文字のテキスト配置を取得します。
getTextAttributeIndices()Integer[]個別のテキスト形式実行の開始に対応するテキスト インデックスのセットを取得します。
getType()ElementType要素の ElementType を取得します。
insertText(offset, text)Text特定の文字オフセットに、指定されたテキストを挿入します。
isAtDocumentEnd()Boolean要素が Document の最後にあるかどうかを判断します。
isBold()Boolean太字の設定を取得します。
isBold(offset)Boolean指定された文字オフセットでの太字設定を取得します。
isItalic()Boolean斜体の設定を取得します。
isItalic(offset)Boolean指定された文字オフセットでの斜体設定を取得します。
isStrikethrough()Boolean取り消し線の設定を取得します。
isStrikethrough(offset)Boolean指定された文字オフセットで取り消し線設定を取得します。
isUnderline()Boolean下線の設定を取得します。
isUnderline(offset)Boolean指定された文字オフセットの下線設定を取得します。
merge()Text要素を同じ型の前の兄弟と結合します。
removeFromParent()Text親から要素を削除します。
replaceText(searchPattern, replacement)Element正規表現を使用して、指定されたテキスト パターンをすべて置換文字列に置き換えます。
setAttributes(startOffset, endOffsetInclusive, attributes)Text指定された属性を指定された文字範囲に適用します。
setAttributes(attributes)Text要素の属性を設定します。
setBackgroundColor(startOffset, endOffsetInclusive, color)Text指定した文字範囲の背景色を設定します。
setBackgroundColor(color)Text背景色を設定します。
setBold(bold)Text太字を設定します。
setBold(startOffset, endOffsetInclusive, bold)Text指定した文字範囲を太字に設定します。
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)Text指定した文字範囲のフォント ファミリーを設定します。
setFontFamily(fontFamilyName)Textフォント ファミリーを設定します。
setFontSize(startOffset, endOffsetInclusive, size)Text指定した文字範囲のフォントサイズを設定します。
setFontSize(size)Textフォントサイズを設定します。
setForegroundColor(startOffset, endOffsetInclusive, color)Text指定した文字範囲の前景色を設定します。
setForegroundColor(color)Text前景色を設定します。
setItalic(italic)Text斜体の設定を行います。
setItalic(startOffset, endOffsetInclusive, italic)Text指定された文字範囲に斜体を設定します。
setLinkUrl(startOffset, endOffsetInclusive, url)Text指定した文字範囲のリンク URL を設定します。
setLinkUrl(url)Textリンク URL を設定します。
setStrikethrough(strikethrough)Text取り消し線の設定を行います。
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)Text指定した文字範囲に取り消し線を設定します。
setText(text)Textテキストの内容を設定します。
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)Text特定の文字範囲のテキストの配置を設定します。
setTextAlignment(textAlignment)Textテキストの配置を設定します。
setUnderline(underline)Text下線を設定。
setUnderline(startOffset, endOffsetInclusive, underline)Text指定した文字範囲に下線を設定します。

詳細なドキュメント

appendText(text)

指定したテキストをこのテキスト領域の末尾に追加します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Adds the text, 'Sample body text,' to the end of the document body.
const text = body.editAsText().appendText('Sample body text');

パラメータ

氏名説明
textString追加するテキスト。

戻る

Text - 現在の要素。

承認

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

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

copy()

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

その要素に存在する子要素もコピーされます。新しい要素に親がありません。

戻る

Text - 新しいコピー。

承認

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

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

deleteText(startOffset, endOffsetInclusive)

テキストの範囲を削除します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
 const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Deletes the first 10 characters in the body.
 const text = body.editAsText().deleteText(0, 9);

パラメータ

氏名説明
startOffsetInteger最初に削除する文字の文字オフセット。
endOffsetInclusiveInteger削除する最後の文字の文字オフセット。

戻る

Text - 現在の要素。

承認

このメソッドを使用するスクリプトには、次の 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 - 現在の要素のテキスト バージョン。


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

getAttributes(offset)

指定された文字オフセットにある属性を取得します。

その結果、各有効なテキスト属性のプロパティを含むオブジェクトが作成され、各プロパティ名は DocumentApp.Attribute 列挙型のアイテムに対応します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Declares style attributes.
const style = {}
style[DocumentApp.Attribute.BOLD] = true;
style[DocumentApp.Attribute.ITALIC] = true;
style[DocumentApp.Attribute.FONT_SIZE] = 29;

// Sets the style attributes to the document body.
const text = body.editAsText();
text.setAttributes(style);

// Gets the style attributes applied to the eleventh character in the
// body and logs them to the console.
const attributes = text.getAttributes(10);
console.log(attributes);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

Object - 要素の属性。

承認

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

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

getBackgroundColor()

背景色の設定を取得します。

戻る

String - 背景色。CSS 表記('#ffffff' など)でフォーマットします。この属性に複数の値が含まれている場合は null です。

承認

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

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

getBackgroundColor(offset)

指定された文字オフセットの背景色を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456');

// Gets the document body.
const body = doc.getBody();

// Sets the background color of the first 3 characters in the body.
const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB');

// Gets the background color of the first character in the body.
const backgroundColor = text.getBackgroundColor(0);

// Logs the background color to the console.
console.log(backgroundColor);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

String - 背景色('#ffffff' などの CSS 表記形式)。

承認

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

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

getFontFamily()

フォント ファミリーの設定を取得します。名前は、ドキュメントの [フォント] メニューまたは Google Fonts のフォントで指定できます。大文字と小文字が区別されます。getFontFamily() メソッドと setFontFamily(fontFamilyName) メソッドで、FontFamily 列挙型ではなく、文字列名がフォントに使用されるようになりました。この列挙型はサポートが終了していますが、古いスクリプトとの互換性を維持するために引き続き使用できます。

戻る

String - フォント ファミリー。要素に複数の属性が含まれている場合には null を指定します。

承認

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

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

getFontFamily(offset)

指定された文字オフセットでフォント ファミリーを取得します。名前は、ドキュメントの [フォント] メニューまたは Google Fonts の任意のフォントにできます。大文字と小文字が区別されます。getFontFamily() メソッドと setFontFamily(fontFamilyName) メソッドで、FontFamily 列挙型の代わりにフォントに文字列名が使用されるようになりました。この列挙型はサポートが終了していますが、古いスクリプトとの互換性を維持するために引き続き使用できます。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the font of the first 16 characters to Impact.
const text = body.editAsText().setFontFamily(0, 15, 'Impact');

// Gets the font family of the 16th character in the document body.
const fontFamily = text.getFontFamily(15);

// Logs the font family to the console.
console.log(fontFamily);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

String - フォント ファミリー。

承認

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

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

getFontSize()

フォントサイズの設定を取得します。

戻る

Number - フォントサイズ。要素にこの属性に複数の値が含まれている場合は null です。

承認

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

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

getFontSize(offset)

指定された文字オフセットでのフォントサイズを取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the font size of the first 13 characters to 15.
const text = body.editAsText().setFontSize(0, 12, 15);

// Gets the font size of the first character.
const fontSize = text.getFontSize(0);

// Logs the font size to the console.
console.log(fontSize);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

Number - フォントサイズ。

承認

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

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

getForegroundColor()

前景色の色設定を取得します。

戻る

String - CSS 表記('#ffffff' など)の形式で指定された前景色。要素に複数の値がこの属性に含まれている場合は null です。

承認

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

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

getForegroundColor(offset)

指定された文字オフセットで前景色を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the foreground color of the first 3 characters in the document body.
const text = body.editAsText().setForegroundColor(0, 2, '#0000FF');

// Gets the foreground color of the first character in the document body.
const foregroundColor = text.getForegroundColor(0);

// Logs the foreground color to the console.
console.log(foregroundcolor);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

String - CSS 表記形式('#ffffff' など)の前景色。

承認

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

getLinkUrl(offset)

指定された文字オフセットでリンク URL を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Applies a link to the first 10 characters in the body.
const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/');

// Gets the URL of the link from the first character.
const link = text.getLinkUrl(0);

// Logs the link URL to the console.
console.log(link);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

String - リンク URL。

承認

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

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

getTextAlignment(offset)

1 文字のテキスト配置を取得します。使用できる配置のタイプは、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT です。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the text alignment of the document body to NORMAL.
const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL);

// Gets the text alignment of the ninth character.
const alignment = text.getTextAlignment(8);

// Logs the text alignment to the console.
console.log(alignment.toString());

パラメータ

氏名説明
offsetInteger文字のオフセット。

戻る

TextAlignment - テキストの配置のタイプ。または、テキストの配置が設定されていない場合は null です。

承認

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

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

getTextAttributeIndices()

個別のテキスト形式実行の開始に対応するテキスト インデックスのセットを取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Gets the text indices at which text formatting changes.
const indices = body.editAsText().getTextAttributeIndices();

// Logs the indices to the console.
console.log(indices.toString());

戻る

Integer[] - テキスト形式を変更するテキスト インデックスのセット。

承認

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

insertText(offset, text)

指定された文字オフセットに、指定されたテキストを挿入します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Inserts the text, 'Sample inserted text', at the start of the body content.
const text = body.editAsText().insertText(0, 'Sample inserted text');

パラメータ

氏名説明
offsetIntegerテキストを挿入する文字オフセット。
textString挿入するテキスト。

戻る

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

isBold()

太字の設定を取得します。

戻る

Boolean - テキストを太字にするか、要素にこの属性に複数の値が含まれている場合は null を指定します。

承認

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

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

isBold(offset)

指定された文字オフセットで太字の設定を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Bolds the first 4 characters in the document body.
const text = body.editAsText().setBold(0, 3, true);

// Gets whether or not the text is bold.
const bold = text.editAsText().isBold(0);

// Logs the text's bold setting to the console
console.log(bold);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

Boolean - 太字の設定。

承認

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

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

isItalic()

斜体の設定を取得します。

戻る

Boolean - テキストを斜体に設定するか、要素にこの属性に複数の値が含まれる場合は null かどうかを示します。

承認

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

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

isItalic(offset)

指定された文字オフセットの斜体設定を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 13 characters of the document body to italic.
const text = body.editAsText().setItalic(0, 12, true);

// Gets whether the fifth character in the document body is set to
// italic and logs it to the console.
const italic = text.isItalic(4);
console.log(italic);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

Boolean - 斜体の設定。

承認

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

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

isStrikethrough()

取り消し線の設定を取得します。

戻る

Boolean - テキストに取り消し線を付けるか、要素にこの属性に複数の値が含まれている場合は null を指定します。

承認

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

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

isStrikethrough(offset)

指定された文字オフセットで取り消し線設定を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 17 characters of the document body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 16, true);

// Gets whether the first character in the document body is set to
// strikethrough and logs it to the console.
const strikethrough = text.isStrikethrough(0);
console.log(strikethrough);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

Boolean - 取り消し線設定。

承認

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

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

isUnderline()

下線の設定を取得します。

戻る

Boolean - テキストに下線を付けるか、要素にこの属性に複数の値が含まれている場合は null を指定します。

承認

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

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

isUnderline(offset)

指定された文字オフセットの下線設定を取得します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 13 characters of the document body to underline.
const text = body.editAsText().setUnderline(0, 12, false);

// Gets whether the first character in the document body is set to
// underline and logs it to the console
const underline = text.editAsText().isUnderline(0);
console.log(underline);

パラメータ

氏名説明
offsetInteger文字オフセット。

戻る

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

戻る

Text - マージされた要素。

承認

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

戻る

Text - 削除された要素。

承認

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

指定した属性を指定の文字範囲に適用します。

指定する属性パラメータは、各プロパティ名が DocumentApp.Attribute 列挙の項目で、各プロパティ値が適用する新しい値であるオブジェクトである必要があります。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body and edits as text.
const body = doc.getBody().editAsText();

// Declares style attributes for font size and font family.
const style = {}
style[DocumentApp.Attribute.FONT_SIZE] = 20 ;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact';

// Sets the style attributes to the first 9 characters in the document body.
const text = body.setAttributes(0, 8, style);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
attributesObject要素の属性。

戻る

Text - 現在の要素。

承認

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

戻る

Text - 現在の要素。

承認

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

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

指定した文字範囲の背景色を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the background color of the first 3 characters in the
// document body to hex color #0000FF.
const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
colorString背景色(CSS 表記形式)(例: '#ffffff')。

戻る

Text - 現在の要素。

承認

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

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

setBackgroundColor(color)

背景色を設定します。

パラメータ

氏名説明
colorString背景色: CSS 表記形式(例: '#ffffff'

戻る

Text - 現在の要素。

承認

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

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

setBold(bold)

太字を設定します。

パラメータ

氏名説明
boldBoolean太字の設定

戻る

Text - 現在の要素。

承認

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

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

setBold(startOffset, endOffsetInclusive, bold)

指定した文字範囲を太字に設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 11 characters in the document body to bold.
const text = body.editAsText().setBold(0, 10, true);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
boldBoolean太字の設定

戻る

Text - 現在の要素。

承認

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

指定した文字範囲のフォント ファミリーを設定します。名前は、ドキュメントの [フォント] メニューまたは Google Fonts の任意のフォントにすることができます。大文字と小文字が区別されます。認識できないフォント名は Arial として表示されます。getFontFamily(offset) メソッドと setFontFamily(fontFamilyName) メソッドで、FontFamily 列挙型の代わりにフォントに文字列名が使用されるようになりました。この列挙型はサポートが終了していますが、古いスクリプトとの互換性を維持するために引き続き使用できます。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets body of the document.
const body = doc.getBody();

// Sets the font of the first 4 characters in the document body to Roboto.
const text = body.editAsText().setFontFamily(0, 3, 'Roboto');

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
fontFamilyNameStringドキュメントのフォント ファミリーの名前(ドキュメントまたは Google Fonts)

戻る

Text - 現在の要素。

承認

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

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

setFontFamily(fontFamilyName)

フォント ファミリーを設定します。名前は、ドキュメントの [フォント] メニューまたは Google Fonts のフォントで指定できます。大文字と小文字が区別されます。認識されないフォント名は Arial としてレンダリングされます。getFontFamily() メソッドと setFontFamily(fontFamilyName) メソッドで、FontFamily 列挙型の代わりにフォントに文字列名が使用されるようになりました。この列挙型はサポートが終了していますが、古いスクリプトとの互換性を維持するために引き続き使用できます。

パラメータ

氏名説明
fontFamilyNameStringフォント ファミリーの名前(ドキュメントの [フォント] メニューまたは Google Fonts)

戻る

Text - 現在の要素。

承認

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

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

setFontSize(startOffset, endOffsetInclusive, size)

指定した文字範囲のフォントサイズを設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the size of the first 11 characters in the document body to 12.
const text = body.editAsText().setFontSize(0, 10, 12);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
sizeNumberフォントサイズ。

戻る

Text - 現在の要素。

承認

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

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

setFontSize(size)

フォントサイズを設定します。

パラメータ

氏名説明
sizeNumberフォントサイズ

戻る

Text - 現在の要素。

承認

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

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

setForegroundColor(startOffset, endOffsetInclusive, color)

指定した文字範囲の前景色を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the foreground color of the first 2 characters in the
// document body to hex color #FF0000.
const text = body.editAsText().setForegroundColor(0, 1, '#FF0000');

// Gets the foreground color for the second character in the document body.
const foregroundColor = text.getForegroundColor(1);

//  Logs the foreground color to the console.
console.log(foregroundColor);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
colorString前景色。CSS 表記('#ffffff' など)で指定します。

戻る

Text - 現在の要素。

承認

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

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

setForegroundColor(color)

前景色を設定します。

パラメータ

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

戻る

Text - 現在の要素。

承認

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

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

setItalic(italic)

斜体の設定を行います。

パラメータ

氏名説明
italicBoolean斜体の設定

戻る

Text - 現在の要素。

承認

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

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

setItalic(startOffset, endOffsetInclusive, italic)

指定した文字範囲に斜体を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 11 characters in the document body to italic.
const text = body.editAsText().setItalic(0, 10, true);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
italicBoolean斜体の設定にします。

戻る

Text - 現在の要素。

承認

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

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

setLinkUrl(startOffset, endOffsetInclusive, url)

指定した文字範囲のリンク URL を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Applies a link to the first 11 characters in the body.
const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
urlStringリンク URL。

戻る

Text - 現在の要素。

承認

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

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

setLinkUrl(url)

リンク URL を設定します。

パラメータ

氏名説明
urlStringリンク URL

戻る

Text - 現在の要素。

承認

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

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

setStrikethrough(strikethrough)

取り消し線の設定を行います。

パラメータ

氏名説明
strikethroughBoolean取り消し線の設定

戻る

Text - 現在の要素。

承認

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

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

setStrikethrough(startOffset, endOffsetInclusive, strikethrough)

指定した文字範囲に取り消し線を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 11 characters in the document body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 10, true);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
strikethroughBoolean取り消し線の設定

戻る

Text - 現在の要素。

承認

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

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

setText(text)

テキスト コンテンツを設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Replaces the contents of the body with the text, 'New body text.'
const text = body.editAsText().setText('New body text.');

パラメータ

氏名説明
textString新しいテキストの内容。

戻る

Text - 現在の要素。

承認

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

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

特定の文字範囲のテキストの配置を設定します。使用可能な配置のタイプは、DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT です。

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

パラメータ

氏名説明
startOffsetInteger文字範囲の開始オフセット。
endOffsetInclusiveInteger文字範囲の終了オフセット(その値も含む)。
textAlignmentTextAlignment適用するテキストの配置のタイプ。

戻る

Text - 現在の要素。

承認

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

戻る

Text - 現在の要素。

承認

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

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

setUnderline(underline)

下線を設定。

パラメータ

氏名説明
underlineBoolean下線を設定

戻る

Text - 現在の要素。

承認

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

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

setUnderline(startOffset, endOffsetInclusive, underline)

指定した文字範囲に下線を設定します。

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the first 11 characters in the document body to underline.
const text = body.editAsText().setUnderline(0, 10, true);

パラメータ

氏名説明
startOffsetIntegerテキスト範囲の開始オフセット。
endOffsetInclusiveIntegerテキスト範囲の終了オフセット。
underlineBoolean下線の設定。

戻る

Text - 現在の要素。

承認

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

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