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.CellFormatfrom simple keyword arguments. Pass aStyletostyle()orstyle().Only the properties you pass are written. Anything left as
Noneis omitted from the compiledCellFormat, so applying aStylenever 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
Noneto leave unchanged.text_color (str | None) – Text color as a hex string, or
Noneto leave unchanged.horizontal_align (str | None) –
"left","center","right", orNone.vertical_align (str | None) –
"top","middle","bottom", orNone.bold (bool | None) – Bold text.
Noneleaves it unchanged.italic (bool | None) – Italic text.
Noneleaves it unchanged.strikethrough (bool | None) – Strikethrough text.
Noneleaves 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))))