Class RichTextValueBuilder Stay organized with collections Save and categorize content based on your preferences.
Page Summary
RichTextValueBuilderis used to create Rich Text values.The builder includes methods to set text, apply text styles, and set link URLs.
Styles and link URLs can be applied to the entire value or specific substrings using offsets.
The
build()method finalizes the creation of theRichTextValue.
A builder for Rich Text values.
Methods
| Method | Return type | Brief description |
|---|---|---|
build() | Rich | Creates a Rich Text value from this builder. |
set | Rich | Sets the link URL for the given substring of this value, or clears it iflink isnull. |
set | Rich | Sets the link URL for the entire value, or clears it iflink isnull. |
set | Rich | Sets the text for this value and clears any existing text style. |
set | Rich | Applies a text style to the given substring of this value. |
set | Rich | Applies a text style to the entire value. |
Detailed documentation
build()
Creates a Rich Text value from this builder.
Return
Rich — A Rich Text value created from this builder.
setLinkUrl(startOffset, endOffset, linkUrl)
Sets the link URL for the given substring of this value, or clears it iflink isnull.
// 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.constboldStyle=SpreadsheetApp.newTextStyle().setUnderline(false).setBold(true).setForegroundColor('#000000').build();constvalue=SpreadsheetApp.newRichTextValue().setText('foo no baz').setLinkUrl(0,3,'https://bar.foo').setLinkUrl(7,10,'https://abc.xyz').setTextStyle(7,10,boldStyle).build();
Parameters
| Name | Type | Description |
|---|---|---|
start | Integer | The start offset for the substring, inclusive. |
end | Integer | The end offset for the substring, exclusive. |
link | String | The link URL being set. |
Return
Rich — This builder, for chaining.
setLinkUrl(linkUrl)
Sets the link URL for the entire value, or clears it iflink isnull.
// Creates a Rich Text value for the text "Foo" which points to// "https://bar.foo".constvalue=SpreadsheetApp.newRichTextValue().setText('Foo').setLinkUrl('https://bar.foo').build();
Parameters
| Name | Type | Description |
|---|---|---|
link | String | The link URL being set. |
Return
Rich — This builder, for chaining.
setText(text)
Sets the text for this value and clears any existing text style. When creating a new Rich Textvalue, this should be called beforeset.
Parameters
| Name | Type | Description |
|---|---|---|
text | String | The text for this value. |
Return
Rich — This builder, for chaining.
setTextStyle(startOffset, endOffset, textStyle)
Applies a text style to the given substring of this value. Offsets are 0 based and are relativeto the cell's text value. Does nothing iftext isnull.
// Creates a Rich Text value for the text "HelloWorld", with "Hello" bolded, and// "World" italicized.constbold=SpreadsheetApp.newTextStyle().setBold(true).build();constitalic=SpreadsheetApp.newTextStyle().setItalic(true).build();constvalue=SpreadsheetApp.newRichTextValue().setText('HelloWorld').setTextStyle(0,5,bold).setTextStyle(5,10,italic).build();
Parameters
| Name | Type | Description |
|---|---|---|
start | Integer | The start offset for the substring, inclusive. |
end | Integer | The end offset for the substring, exclusive. |
text | Text | The text style being set. |
Return
Rich — This builder, for chaining.
setTextStyle(textStyle)
Applies a text style to the entire value. Previously set text styles are only affected if theyare directly overwritten by values withintext. Does nothing iftextisnull.
// Creates a Rich Text value for the text "HelloWorld" with "Hello" bolded and// italicized, and "World" only italicized.constbold=SpreadsheetApp.newTextStyle().setBold(true).build();constitalic=SpreadsheetApp.newTextStyle().setItalic(true).build();constvalue=SpreadsheetApp.newRichTextValue().setText('HelloWorld').setTextStyle(0,5,bold).setTextStyle(italic).build();
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style being set. |
Return
Rich — This builder, for chaining.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.