Style

class Style(bg_color=None, text_color=None, horizontal_align=None, vertical_align=None, bold=None, italic=None, strikethrough=None, raw=None)

Builds a gspread_formatting.CellFormat from simple keyword arguments. Pass a Style to style() or style().

Only the properties you pass are written. Anything left as None is omitted from the compiled CellFormat, so applying a Style never clobbers formatting you did not set — Style(bold=True) makes a cell bold without touching its existing background, text color, or alignment.

Parameters:
  • bg_color (str | None) – Background color as a hex string, or None to leave unchanged.

  • text_color (str | None) – Text color as a hex string, or None to leave unchanged.

  • horizontal_align (str | None) – "left", "center", "right", or None.

  • vertical_align (str | None) – "top", "middle", "bottom", or None.

  • bold (bool | None) – Bold text. None leaves it unchanged.

  • italic (bool | None) – Italic text. None leaves it unchanged.

  • strikethrough (bool | None) – Strikethrough text. None leaves it unchanged.

  • raw (CellFormat | None) – A pre-built gspread_formatting.CellFormat. When provided, all other arguments are ignored.

Examples

Header row with background color:

from betterspread import Style

header_style = Style(
    bg_color="#4a86e8",
    text_color="#ffffff",
    bold=True,
    horizontal_align="center",
)
await row.style(header_style)

Warning cell with italic text:

await cell.style(Style(bg_color="#fff2cc", italic=True))

Passing a raw CellFormat directly:

from gspread_formatting import CellFormat, Color

await cell.style(Style(raw=CellFormat(backgroundColor=Color(1, 0.8, 0))))