Class RichTextValueBuilder

RichTextValueBuilder

RTF 值的建構工具。

方法

方法傳回類型簡短說明
build()RichTextValue使用此建構工具建立 RTF 格式的值。
setLinkUrl(startOffset, endOffset, linkUrl)RichTextValueBuilder為這個值指定的子字串設定連結網址,如果 linkUrlnull,則會清除網址。
setLinkUrl(linkUrl)RichTextValueBuilder為整個值設定連結網址,如果 linkUrlnull,則會清除網址。
setText(text)RichTextValueBuilder設定這個值的文字,並清除任何現有的文字樣式。
setTextStyle(startOffset, endOffset, textStyle)RichTextValueBuilder將文字樣式套用至這個值的特定子字串。
setTextStyle(textStyle)RichTextValueBuilder將文字樣式套用至整個值。

內容詳盡的說明文件

build()

使用此建構工具建立 RTF 格式的值。

回攻員

RichTextValue — 從這個建構工具建立的 RTF 值。


setLinkUrl(startOffset, endOffset, linkUrl)

為這個值指定的子字串設定連結網址,如果 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要設定的連結網址。

回攻員

RichTextValueBuilder — 這個建構工具用於鏈結。


setLinkUrl(linkUrl)

為整個值設定連結網址,如果 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要設定的連結網址。

回攻員

RichTextValueBuilder — 這個建構工具用於鏈結。


setText(text)

設定這個值的文字,並清除任何現有的文字樣式。建立新的 RTF 值時,應在 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 — 這個建構工具用於鏈結。