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 ExcelManager instance with a table already defined via set_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:

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:
  • type (str) – Font family name.

  • size (float) – Font size in points.

  • bold (bool) – Bold text.

  • italic (bool) – Italic text.

  • hex_color (str) – 8-character ARGB or 6-character RGB hex string for the font colour.

Raises:

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:
  • horizontal (str) – Horizontal alignment. One of: "left", "center", "right", "fill", "justify", "centerContinuous", "distributed".

  • vertical (str) – Vertical alignment. One of: "top", "center", "bottom", "justify", "distributed".

  • wrap_text (bool) – Wrap text within the cell.

Raises:

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:

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:

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:

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:
  • type (str) – Font family name.

  • size (float) – Font size in points.

  • bold (bool) – Bold text.

  • italic (bool) – Italic text.

  • hex_color (str) – 8-character ARGB or 6-character RGB hex string.

Raises:

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:
  • horizontal (str) – Horizontal alignment.

  • vertical (str) – Vertical alignment.

  • wrap_text (bool) – Wrap text within the cell.

Raises:
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:
freeze_header()[source]

Freeze the pane below the last header row.

Raises:

Example:

excel.set_table("A1", "D20")
excel.define_header(rows=2)
style = ExcelStyle(excel)
style.freeze_header()
# Freeze pane is set at "A3"