-
-
Notifications
You must be signed in to change notification settings - Fork 1
Format API
Format is a chainable cell-style object. Every setter returns self, so styles compose in one expression:
from rustpy_xlsxwriter import FastExcel, Format
money = Format().set_num_format("$#,##0.00").set_bold().set_font_color("green")
header = Format().set_bold().set_background_color("#305496").set_font_color("white")
(
FastExcel("styled.xlsx")
.sheet(
"Sales",
records,
header_format=header,
column_formats={"amount": money},
)
.save()
)| Where | Scope |
|---|---|
header_format= on .sheet()
|
every header cell of that sheet |
column_formats={name: Format} |
a whole column (by header name) |
column_formats=[Format, None, ...] |
columns by position |
A column_formats entry wins over the sheet-wide float_format / datetime_format for that column.
Font: set_bold, set_italic, set_font_strikethrough, set_font_size(f), set_font_name(s), set_font_color(c), set_font_script(s), set_font_family(n), set_font_charset(n), set_font_scheme(s), set_underline(style="single")
Fill: set_background_color(c), set_foreground_color(c), set_pattern(p)
Border: set_border(style), set_border_color(c), plus per-side set_border_top/bottom/left/right(_color) and set_border_diagonal(_color/_type)
Alignment: set_align(a), set_text_wrap, set_rotation(deg), set_indent(n), set_shrink, set_reading_direction(n)
Numbers: set_num_format(fmt), set_num_format_index(i)
Protection: set_locked, set_unlocked, set_hidden
Misc: set_quote_prefix, set_checkbox, set_hyperlink
Accepts a hex string ("#RRGGBB" or "RRGGBB") or a name: black, blue, brown, cyan, gray/grey, green, lime, magenta, navy, orange, pink, purple, red, silver, white, yellow, automatic.
Format().set_font_color("#FF8800")
Format().set_background_color("navy")-
align:
general, left, center, right, fill, justify, center_across, distributed, top, bottom, vcenter, vjustify, vdistributed -
border:
none, thin, medium, dashed, dotted, thick, double, hair, medium_dashed, dash_dot, medium_dash_dot, dash_dot_dot, medium_dash_dot_dot, slant_dash_dot -
underline:
none, single, double, single_accounting, double_accounting -
script:
none, super/superscript, sub/subscript
Invalid values raise ValueError with the list of accepted options.