ExcelStyle
- class exceltablekit.excel.styles.ExcelStyle(excel)[source]
High-level styling façade over
ExcelManager. Constructs openpyxl style objects from plain Python values and delegates to the manager for application and file persistence.- Parameters:
excel (ExcelManager) – A configured
ExcelManagerinstance with a table already defined viaset_table().
Body styling
- set_background(hex_color)[source]
Apply a solid background fill to all body cells.
- Parameters:
hex_color (str) – 6-character RGB hex string without
#(e.g."E8F4FD").- Raises:
TableNotDefinedError – If the table is not defined.
TableBackgroundError – If openpyxl fails to apply the fill.
Example:
style.set_background("E8F4FD")
- set_font(type='Time New Roman', size=10.0, bold=False, italic=False, hex_color='FFFF0000')[source]
Apply a font style to all body cells.
- Parameters:
- Raises:
TableNotDefinedError – If the table is not defined.
TableFontError – If openpyxl fails to apply the font.
Example:
style.set_font(type="Calibri", size=11.0, bold=True, hex_color="000000")
- set_alignment(horizontal='left', vertical='center', wrap_text=False)[source]
Apply text alignment to all body cells.
- Parameters:
- Raises:
TableNotDefinedError – If the table is not defined.
TableAlignmentError – If openpyxl fails to apply the alignment.
Example:
style.set_alignment(horizontal="center", vertical="center")
- set_border(left=True, left_style='thin', right=True, right_style='thin', top=True, top_style='thin', bottom=True, bottom_style='thin', hex_color='000000')[source]
Apply a border to all body cells.
- Parameters:
left (bool) – Enable left edge.
left_style (BorderStyle) – Style for the left edge.
right (bool) – Enable right edge.
right_style (BorderStyle) – Style for the right edge.
top (bool) – Enable top edge.
top_style (BorderStyle) – Style for the top edge.
bottom (bool) – Enable bottom edge.
bottom_style (BorderStyle) – Style for the bottom edge.
hex_color (str) – 6-character RGB hex colour for all border edges.
- Raises:
TableNotDefinedError – If the table is not defined.
TableBorderError – If openpyxl fails to apply the border.
Example:
style.set_border(bottom_style="medium", hex_color="444444")
- auto_fit_columns()[source]
Adjust column widths to fit the longest cell value (header + body) plus 2 characters of padding.
- Raises:
TableNotDefinedError – If the table is not defined.
TableColumnWidthError – If openpyxl fails to set column widths.
Header styling
- set_header_background(hex_color)[source]
Apply a solid background fill to all header cells.
- Parameters:
hex_color (str) – 6-character RGB hex string without
#.- Raises:
TableNotDefinedError – If the table is not defined.
HeaderTableNotDefinedError – If no header rows have been defined.
HeaderTableBackgroundError – If openpyxl fails to apply the fill.
Example:
style.set_header_background("1F4E79")
- set_header_font(type='Time New Roman', size=10.0, bold=False, italic=False, hex_color='FFFF0000')[source]
Apply a font style to all header cells.
- Parameters:
- Raises:
TableNotDefinedError – If the table is not defined.
HeaderTableNotDefinedError – If no header rows have been defined.
HeaderTableFontError – If openpyxl fails to apply the font.
Example:
style.set_header_font(bold=True, size=12.0, hex_color="FFFFFF")
- set_header_alignment(horizontal='left', vertical='center', wrap_text=False)[source]
Apply text alignment to all header cells.
- Parameters:
- Raises:
TableNotDefinedError – If the table is not defined.
HeaderTableNotDefinedError – If no header rows have been defined.
HeaderTableAlignmentError – If openpyxl fails to apply the alignment.
- set_header_border(left=True, left_style='thin', right=True, right_style='thin', top=True, top_style='thin', bottom=True, bottom_style='thin', hex_color='000000')[source]
Apply a border to all header cells. Same parameters as
set_border().- Raises:
TableNotDefinedError – If the table is not defined.
HeaderTableNotDefinedError – If no header rows have been defined.
HeaderTableBorderError – If openpyxl fails to apply the border.
- freeze_header()[source]
Freeze the pane below the last header row.
- Raises:
TableNotDefinedError – If the table is not defined.
HeaderTableNotDefinedError – If no header rows have been defined.
HeaderTableFreezeError – If openpyxl fails to set the freeze pane.
Example:
excel.set_table("A1", "D20") excel.define_header(rows=2) style = ExcelStyle(excel) style.freeze_header() # Freeze pane is set at "A3"