Class TextStyle | Apps Script | Google for Developers (original) (raw)
Class TextStyle
Stay organized with collections Save and categorize content based on your preferences.
TextStyle
The rendered style of text in a cell.
Text styles can have a corresponding [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
. If the [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue.getRuns()](/apps-script/reference/spreadsheet/rich-text-value#getRuns%28%29)
method.
Methods
Method | Return type | Brief description |
---|---|---|
copy() | TextStyleBuilder | Creates a text style builder initialized with the values of this text style. |
getFontFamily() | String | Gets the font family of the text. |
getFontSize() | Integer | Gets the font size of the text in points. |
getForegroundColorObject() | Color | Gets the font color of the text. |
isBold() | Boolean | Gets whether or not the text is bold. |
isItalic() | Boolean | Gets whether or not the cell is italic. |
isStrikethrough() | Boolean | Gets whether or not the cell has strikethrough. |
isUnderline() | Boolean | Gets whether or not the cell is underlined. |
Deprecated methods
Method | Return type | Brief description |
---|---|---|
String | Gets the font color of the text. |
Detailed documentation
copy()
Creates a text style builder initialized with the values of this text style.
Return
[TextStyleBuilder](/apps-script/reference/spreadsheet/text-style-builder)
— 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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
has multiple runs with different font colors.
Return
[Color](/apps-script/reference/spreadsheet/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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
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 [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
has multiple runs with different underline settings.
Return
Boolean
— Whether or not the cell is underlined, or null
.
Deprecated methods
getForegroundColor()
getForegroundColor()
Deprecated. Replaced by [getForegroundColorObject()](#getForegroundColorObject%28%29)
Gets the font color of the text. Returns null
if the font color isn't set or the corresponding [RichTextValue](/apps-script/reference/spreadsheet/rich-text-value)
has multiple runs with different font colors.
Return
String
— The font color of the text as a hex CSS value (for example, "#ff0000") or null
.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-03 UTC.