Class TextStyle Stay organized with collections Save and categorize content based on your preferences.
Page Summary
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 return
null.To avoid getting
nullwhen 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().
The rendered style of text in a cell.
Text styles can have a correspondingRich. If theRich 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 theRich method.
Methods
| Method | Return type | Brief description |
|---|---|---|
copy() | Text | Creates a text style builder initialized with the values of this text style. |
get | String | Gets the font family of the text. |
get | Integer | Gets the font size of the text in points. |
get | Color|null | Gets the font color of the text. |
is | Boolean | Gets whether or not the text is bold. |
is | Boolean | Gets whether or not the cell is italic. |
is | Boolean | Gets whether or not the cell has strikethrough. |
is | Boolean | Gets whether or not the cell is underlined. |
Deprecated methods
| Method | Return type | Brief description |
|---|---|---|
| String|null | Gets the font color of the text. |
Detailed documentation
copy()
Creates a text style builder initialized with the values of this text style.
Return
Text — A builder from this text style.
getFontFamily()
Gets the font family of the text. Returnsnull if the font family isn't set or thecorrespondingRich 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 correspondingRich 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 thecorrespondingRich 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 thecorrespondingRich 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 thecorrespondingRich 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 correspondingRich 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 thecorrespondingRich has multiple runs with different underlinesettings.
Return
Boolean — Whether or not the cell is underlined, ornull.
Deprecated methods
getForegroundColor()
getForegroundColor() Deprecated. Replaced byget
Gets the font color of the text. Returnsnull if the font color isn't set or thecorrespondingRich 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.