Class RichTextValueBuilder

RichTextValueBuilder

A builder for Rich Text values.

Methods

MethodReturn typeBrief description
build()RichTextValueCreates a Rich Text value from this builder.
setText(text)RichTextValueBuilderSets the text for this value and clears any existing text style.
setTextStyle(startOffset, endOffset, textStyle)RichTextValueBuilderApplies a text style to the given substring of this value.
setTextStyle(textStyle)RichTextValueBuilderApplies a text style to the entire value.

Detailed documentation

build()

Creates a Rich Text value from this builder.

Return

RichTextValue — A Rich Text value created from this builder.


setText(text)

Sets the text for this value and clears any existing text style. When creating a new Rich Text value, this should be called before setTextStyle(startOffset, endOffset, textStyle).

Parameters

NameTypeDescription
textStringThe text for this value.

Return

RichTextValueBuilder — The builder for chaining.


setTextStyle(startOffset, endOffset, textStyle)

Applies a text style to the given substring of this value. Offsets are 0 based and are relative to the cell's text value. Does nothing if textStyle is 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();

Parameters

NameTypeDescription
startOffsetIntegerThe start offset for the substring, inclusive.
endOffsetIntegerThe end offset for the substring, exclusive.
textStyleTextStyleThe text style being set.

Return

RichTextValueBuilder — The builder for chaining.


setTextStyle(textStyle)

Applies a text style to the entire value. Previously set text styles are only affected if they are directly overwritten by values within textStyle. Does nothing if textStyle is 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();

Parameters

NameTypeDescription
textStyleTextStyleThe text style being set.

Return

RichTextValueBuilder — The builder for chaining.

Send tilbakemelding om ...

Trenger du hjelp? Gå til brukerstøttesiden vår.