AI-generated Key Takeaways
-
TextStyle
defines the rendered style of text within a cell in Google Sheets, encompassing attributes like font family, size, color, and formatting. -
It can be linked to a
RichTextValue
for more complex formatting but may returnnull
for style properties if theRichTextValue
has multiple runs with differing styles. -
Developers can use methods like
getFontFamily()
,getFontSize()
,isBold()
, etc., to retrieve specific style attributes of the text. -
A
TextStyleBuilder
can be created using thecopy()
method to facilitate the construction of new text styles based on existing ones. -
The
getForegroundColor()
method is deprecated and should be replaced withgetForegroundColorObject()
to retrieve the font color as aColor
object.
The rendered style of text in a cell.
Text styles can have a corresponding Rich
. If the Rich
spans multiple text runs that have different values for a given text style read
method, the method returns null
. To avoid this, query for text styles using the Rich Text
values returned by the Rich
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 | 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. |
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. Returns null
if the font family isn't set or the
corresponding Rich
has multiple runs with different font
families.
Return
String
— The font family of the text (for example, "Arial") or null
.
getFontSize()
Gets the font size of the text in points. Returns null
if the font size isn't set or
the corresponding Rich
has multiple runs with different font
sizes.
Return
Integer
— The font size of the text or null
.
getForegroundColorObject()
Gets the font color of the text. Returns null
if the font color isn't set or the
corresponding Rich
has multiple runs with different font
colors.
Return
Color
— The font color of the text or null
.
isBold()
Gets whether or not the text is bold. Returns null
if bold isn't set or the
corresponding Rich
has multiple runs with different bold
settings.
Return
Boolean
— Whether or not the cell is bold, or null
.
isItalic()
Gets whether or not the cell is italic. Returns null
if italic isn't set or the
corresponding Rich
has multiple runs with different italic
settings.
Return
Boolean
— Whether or not the cell is italic, or null
.
isStrikethrough()
Gets whether or not the cell has strikethrough. Returns null
if strikethrough isn't set
or the corresponding Rich
has multiple runs with different
strikethrough settings.
Return
Boolean
— Whether or not the cell has strikethrough, or null
.
isUnderline()
Gets whether or not the cell is underlined. Returns null
if underline isn't set or the
corresponding Rich
has multiple runs with different underline
settings.
Return
Boolean
— Whether or not the cell is underlined, or null
.