Class RichTextValueBuilder

RichTextValueBuilder

リッチテキスト値のビルダー。

Methods

メソッド戻り値の型概要
build()RichTextValueこのビルダーからリッチテキスト値を作成します。
setLinkUrl(startOffset, endOffset, linkUrl)RichTextValueBuilderこの値で指定された部分文字列のリンク URL を設定するか、linkUrlnull の場合はクリアします。
setLinkUrl(linkUrl)RichTextValueBuilder値全体のリンク URL を設定するか、linkUrlnull の場合はクリアします。
setText(text)RichTextValueBuilderこの値のテキストを設定し、既存のテキスト スタイルをすべてクリアします。
setTextStyle(startOffset, endOffset, textStyle)RichTextValueBuilderこの値の指定された部分文字列にテキスト スタイルを適用します。
setTextStyle(textStyle)RichTextValueBuilder値全体にテキスト スタイルを適用します。

詳細なドキュメント

build()

このビルダーからリッチテキスト値を作成します。

リターン

RichTextValue - このビルダーから作成されたリッチテキスト値。


setLinkUrl(startOffset, endOffset, linkUrl)

この値で指定された部分文字列のリンク URL を設定するか、linkUrlnull の場合はクリアします。

// Creates a Rich Text value for the text "foo no baz" with "foo" pointing to
// "https://bar.foo" and "baz" to "https://abc.xyz".
// "foo" is underlined with the default link color, whereas "baz" has its text style
// overridden by a call to `setTextStyle`, and is therefore black and bold with no underlining.
const boldStyle = SpreadsheetApp.newTextStyle()
    .setUnderline(false)
    .setBold(true)
    .setForegroundColor("#000000")
    .build();
const value = SpreadsheetApp.newRichTextValue()
    .setText("foo no baz")
    .setLinkUrl(0, 3, "https://bar.foo")
    .setLinkUrl(7, 10, "https://abc.xyz")
    .setTextStyle(7, 10, boldStyle)
    .build();

パラメータ

名前説明
startOffsetInteger部分文字列の開始オフセット(この値を含む)。
endOffsetInteger部分文字列の終了オフセット(両端を除く)。
linkUrlString設定されるリンク URL。

リターン

RichTextValueBuilder - チェーン用のこのビルダー。


setLinkUrl(linkUrl)

値全体のリンク URL を設定するか、linkUrlnull の場合はクリアします。

// Creates a Rich Text value for the text "Foo" which points to "https://bar.foo".
const value = SpreadsheetApp.newRichTextValue()
    .setText("Foo")
    .setLinkUrl("https://bar.foo")
    .build();

パラメータ

名前説明
linkUrlString設定されるリンク URL。

リターン

RichTextValueBuilder - チェーン用のこのビルダー。


setText(text)

この値のテキストを設定し、既存のテキスト スタイルをすべてクリアします。新しいリッチテキスト値を作成する場合は、setTextStyle(startOffset, endOffset, textStyle) の前に呼び出す必要があります。

パラメータ

名前説明
textStringこの値のテキスト。

リターン

RichTextValueBuilder - チェーン用のこのビルダー。


setTextStyle(startOffset, endOffset, textStyle)

この値の指定された部分文字列にテキスト スタイルを適用します。オフセットは 0 ベースで、セルのテキスト値を基準にします。textStylenull の場合は何も行いません。

// Creates a Rich Text value for the text "HelloWorld", with "Hello" bolded, and "World"
// italicized.
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
var value = SpreadsheetApp.newRichTextValue()
    .setText("HelloWorld")
    .setTextStyle(0, 5, bold)
    .setTextStyle(5, 10, italic)
    .build();

パラメータ

名前説明
startOffsetInteger部分文字列の開始オフセット(この値を含む)。
endOffsetInteger部分文字列の終了オフセット(両端を除く)。
textStyleTextStyle設定するテキスト スタイル。

リターン

RichTextValueBuilder - チェーン用のこのビルダー。


setTextStyle(textStyle)

値全体にテキスト スタイルを適用します。以前に設定したテキスト スタイルは、textStyle 内の値によって直接上書きされる場合にのみ影響を受けます。textStylenull の場合は何も行いません。

// Creates a Rich Text value for the text "HelloWorld" with "Hello" bolded and italicized,
// and "World" only italicized.
var bold = SpreadsheetApp.newTextStyle().setBold(true).build();
var italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
var value = SpreadsheetApp.newRichTextValue()
    .setText("HelloWorld")
    .setTextStyle(0, 5, bold)
    .setTextStyle(italic)
    .build();

パラメータ

名前説明
textStyleTextStyle設定するテキスト スタイル。

リターン

RichTextValueBuilder - チェーン用のこのビルダー。