RTF 值的建構工具。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
build() | RichTextValue | 使用此建構工具建立 RTF 格式的值。 |
setLinkUrl(startOffset, endOffset, linkUrl) | RichTextValueBuilder | 為這個值指定的子字串設定連結網址,如果 linkUrl 為 null ,則會清除網址。 |
setLinkUrl(linkUrl) | RichTextValueBuilder | 為整個值設定連結網址,如果 linkUrl 為 null ,則會清除網址。 |
setText(text) | RichTextValueBuilder | 設定這個值的文字,並清除任何現有的文字樣式。 |
setTextStyle(startOffset, endOffset, textStyle) | RichTextValueBuilder | 將文字樣式套用至這個值的特定子字串。 |
setTextStyle(textStyle) | RichTextValueBuilder | 將文字樣式套用至整個值。 |
內容詳盡的說明文件
build()
setLinkUrl(startOffset, endOffset, linkUrl)
為這個值指定的子字串設定連結網址,如果 linkUrl
為 null
,則會清除該網址。
// 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();
參數
名稱 | 類型 | 說明 |
---|---|---|
startOffset | Integer | 子字串的起始偏移值 (含首尾)。 |
endOffset | Integer | 子字串的結束偏移值 (不含)。 |
linkUrl | String | 要設定的連結網址。 |
回攻員
RichTextValueBuilder
— 這個建構工具用於鏈結。
setLinkUrl(linkUrl)
為整個值設定連結網址,如果 linkUrl
為 null
,則會清除網址。
// 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();
參數
名稱 | 類型 | 說明 |
---|---|---|
linkUrl | String | 要設定的連結網址。 |
回攻員
RichTextValueBuilder
— 這個建構工具用於鏈結。
setText(text)
設定這個值的文字,並清除任何現有的文字樣式。建立新的 RTF 值時,應在 setTextStyle(startOffset, endOffset, textStyle)
之前呼叫這個值。
參數
名稱 | 類型 | 說明 |
---|---|---|
text | String | 這個值的文字。 |
回攻員
RichTextValueBuilder
— 這個建構工具用於鏈結。
setTextStyle(startOffset, endOffset, textStyle)
將文字樣式套用至這個值的特定子字串。偏移量是以 0 為基準,並與儲存格的文字值相對。如果 textStyle
是 null
,則不會執行任何動作。
// 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();
參數
名稱 | 類型 | 說明 |
---|---|---|
startOffset | Integer | 子字串的起始偏移值 (含首尾)。 |
endOffset | Integer | 子字串的結束偏移值 (不含)。 |
textStyle | TextStyle | 正在設定的文字樣式。 |
回攻員
RichTextValueBuilder
— 這個建構工具用於鏈結。
setTextStyle(textStyle)
將文字樣式套用至整個值。先前設定的文字樣式只會在 textStyle
中的值直接覆寫時,才會受到影響。如果 textStyle
是 null
,則不會執行任何動作。
// 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();
參數
名稱 | 類型 | 說明 |
---|---|---|
textStyle | TextStyle | 正在設定的文字樣式。 |
回攻員
RichTextValueBuilder
— 這個建構工具用於鏈結。