RTF 值的构建器。
方法
方法 | 返回类型 | 简介 |
---|---|---|
build() | RichTextValue | 根据此构建器创建富文本值。 |
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
- 此构建器,用于链接。