Style

class Style(bg_color='#ffffff', text_color='#000000', horizontal_align='left', vertical_align='middle', bold=False, italic=False, strikethrough=False, raw=None)

A dataclass that builds a gspread_formatting.CellFormat from simple keyword arguments. Pass a Style to style() or style().

Parameters:
  • bg_color (str) – Background color as a hex string. Defaults to "#ffffff".

  • text_color (str) – Text color as a hex string. Defaults to "#000000".

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

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

  • bold (bool) – Bold text. Defaults to False.

  • italic (bool) – Italic text. Defaults to False.

  • strikethrough (bool) – Strikethrough text. Defaults to False.

  • 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))))