Class RichTextValueBuilder

RichTextValueBuilder

RTF 值的建構工具。

方法

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

內容詳盡的說明文件

build()

使用這個建構工具建立富文字格式值。

回攻員

RichTextValue:由這個建構工具建立的富文字格式值。


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)

設定此值的文字,並清除任何現有的文字樣式。建立新的 Rich 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. 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:這個建構工具可用於鏈結。