Class TextStyle

  • TextStyle defines the rendered style of text in a cell and can have a corresponding RichTextValue.

  • If a RichTextValue spans multiple text runs with different style values, a method attempting to read that style will returnnull.

  • To avoid gettingnull when querying text styles, use the RichTextValue.getRuns() method.

  • TextStyle provides methods to retrieve font properties like family, size, color, and boolean states for bold, italic, strikethrough, and underline.

  • The getForegroundColor() method is deprecated and has been replaced by getForegroundColorObject().

TextStyle

The rendered style of text in a cell.

Text styles can have a correspondingRichTextValue. If theRichTextValue spans multiple text runs that have different values for a given text style readmethod, the method returnsnull. To avoid this, query for text styles using the Rich Textvalues returned by theRichTextValue.getRuns() method.

Methods

MethodReturn typeBrief description
copy()TextStyleBuilderCreates a text style builder initialized with the values of this text style.
getFontFamily()StringGets the font family of the text.
getFontSize()IntegerGets the font size of the text in points.
getForegroundColorObject()Color|nullGets the font color of the text.
isBold()BooleanGets whether or not the text is bold.
isItalic()BooleanGets whether or not the cell is italic.
isStrikethrough()BooleanGets whether or not the cell has strikethrough.
isUnderline()BooleanGets whether or not the cell is underlined.

Deprecated methods

MethodReturn typeBrief description
getForegroundColor()String|nullGets the font color of the text.

Detailed documentation

copy()

Creates a text style builder initialized with the values of this text style.

Return

TextStyleBuilder — A builder from this text style.


getFontFamily()

Gets the font family of the text. Returnsnull if the font family isn't set or thecorrespondingRichTextValue has multiple runs with different fontfamilies.

Return

String — The font family of the text (for example, "Arial") ornull.


getFontSize()

Gets the font size of the text in points. Returnsnull if the font size isn't set orthe correspondingRichTextValue has multiple runs with different fontsizes.

Return

Integer — The font size of the text ornull.


getForegroundColorObject()

Gets the font color of the text. Returnsnull if the font color isn't set or thecorrespondingRichTextValue has multiple runs with different fontcolors.

Return

Color|null — The font color of the text ornull.


isBold()

Gets whether or not the text is bold. Returnsnull if bold isn't set or thecorrespondingRichTextValue has multiple runs with different boldsettings.

Return

Boolean — Whether or not the cell is bold, ornull.


isItalic()

Gets whether or not the cell is italic. Returnsnull if italic isn't set or thecorrespondingRichTextValue has multiple runs with different italicsettings.

Return

Boolean — Whether or not the cell is italic, ornull.


isStrikethrough()

Gets whether or not the cell has strikethrough. Returnsnull if strikethrough isn't setor the correspondingRichTextValue has multiple runs with differentstrikethrough settings.

Return

Boolean — Whether or not the cell has strikethrough, ornull.


isUnderline()

Gets whether or not the cell is underlined. Returnsnull if underline isn't set or thecorrespondingRichTextValue has multiple runs with different underlinesettings.

Return

Boolean — Whether or not the cell is underlined, ornull.

Deprecated methods

getForegroundColor()

Deprecated. Replaced bygetForegroundColorObject()

Gets the font color of the text. Returnsnull if the font color isn't set or thecorrespondingRichTextValue has multiple runs with different fontcolors.

Return

String|null — The font color of the text as a hex CSS value (for example, "#ff0000") ornull.

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.