RTF 格式值的建構工具。
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
build() | Rich | 從這個建構工具建立 RTF 格式值。 |
set | Rich | 為這個值的指定子字串設定連結網址,或在 link 為 null 時清除連結網址。 |
set | Rich | 為整個值設定連結網址,或在 link 為 null 時清除連結網址。 |
set | Rich | 設定這個值對應的文字,並清除所有現有文字樣式。 |
set | Rich | 將文字樣式套用至這個值的指定子字串。 |
set | Rich | 將文字樣式套用至整個值。 |
內容詳盡的說明文件
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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
start | Integer | 子字串的起始位移 (含)。 |
end | Integer | 子字串的結束位移 (不含)。 |
link | 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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
link | 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. 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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
start | Integer | 子字串的起始位移 (含)。 |
end | Integer | 子字串的結束位移 (不含)。 |
text | Text | 正在設定的文字樣式。 |
回攻員
RichTextValueBuilder:這個建構工具用於串連。
setTextStyle(textStyle)
將文字樣式套用至整個值。只有在先前設定的文字樣式直接遭 textStyle 內的值覆寫時,才會受到影響。如果 textStyle 為 null,則不會執行任何動作。
// 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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | Text | 正在設定的文字樣式。 |
回攻員
RichTextValueBuilder:這個建構工具用於串連。