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.
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const 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.
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const value = SpreadsheetApp.newRichTextValue()
                  .setText('HelloWorld')
                  .setTextStyle(0, 5, bold)
                  .setTextStyle(italic)
                  .build();

參數

名稱類型說明
textStyleTextStyle正在設定的文字樣式。

回攻員

RichTextValueBuilder:這個建構工具用於串連。