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)

设置此值的文本,并清除任何现有的文本样式。创建新的 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.
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();

参数

名称类型说明
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.
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();

参数

名称类型说明
textStyleTextStyle正在设置的文本样式。

弃踢回攻

RichTextValueBuilder - 此构建器,用于链接。