Class ColorBuilder

  • ColorBuilder is a builder for creating color objects in Apps Script spreadsheets.

  • A new ColorBuilder is created using SpreadsheetApp.newColor().

  • The builder allows setting a color as either an RGB color using a CSS string or as a theme color using a ThemeColorType.

  • Once configured, the build() method creates the final Color object.

  • You can also convert a built color object to its RgbColor or ThemeColor representation and get its ColorType.

ColorBuilder

The builder forColorBuilder. To create a new builder, useSpreadsheetApp.newColor().

Methods

MethodReturn typeBrief description
asRgbColor()RgbColorConverts this color to anRgbColor.
asThemeColor()ThemeColorConverts this color to aThemeColor.
build()ColorCreates a color object from the settings supplied to the builder.
getColorType()ColorTypeGet the type of this color.
setRgbColor(cssString)ColorBuilderSets as RGB color.
setThemeColor(themeColorType)ColorBuilderSets as theme color.

Detailed documentation

asRgbColor()

Converts this color to anRgbColor.

Return

RgbColor — The RGB color.

Throws

Error — if the color is not anRgbColor

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

asThemeColor()

Converts this color to aThemeColor.

Return

ThemeColor — The theme color.

Throws

Error — if the color is not aThemeColor.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

build()

Creates a color object from the settings supplied to the builder.

Return

Color — A color object created from this builder.


getColorType()

Get the type of this color.

Return

ColorType — The color type.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setRgbColor(cssString)

Sets as RGB color.

Parameters

NameTypeDescription
cssStringStringThe RGB color in CSS notation (such as '#ffffff').

Return

ColorBuilder — This builder, for chaining.


setThemeColor(themeColorType)

Sets as theme color.

Parameters

NameTypeDescription
themeColorTypeThemeColorTypeThe theme color type.

Return

ColorBuilder — This builder, for chaining.

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.