styler#

class Styler(bg_color: str | None = None, bold: bool = False, font: str = 'Arial', font_size: int | float = 12.0, font_color: str | None = None, number_format: str = 'General', protection: bool = False, underline: str | None = None, border_type: str | Set[str] | Dict[str, str] = 'thin', horizontal_alignment: str = 'center', vertical_alignment: str = 'center', wrap_text: bool = True, shrink_to_fit: bool = True, fill_pattern_type: str = 'solid', indent: int | float = 0.0, comment_author: str | None = None, comment_text: str | None = None, text_rotation: int = 0, date_format: str = 'DD/MM/YY', time_format: str = 'HH:MM', date_time_format: str = 'DD/MM/YY HH:MM', strikethrough: bool = False, italic: bool = False)[source]#

Used to represent a style

Parameters:
  • bg_color (str: one of utils.colors, hex string or color name ie ‘yellow’ Excel supports) – The background color

  • bold (bool) – If True, a bold typeface is used

  • font (str: one of utils.fonts or other font name Excel supports) – The font to use

  • font_size (int) – The font size

  • font_color (str: one of utils.colors, hex string or color name ie ‘yellow’ Excel supports) – The font color

  • number_format (str: one of utils.number_formats or any other format Excel supports) – The format of the cell’s value

  • protection (bool) – If True, the cell/column will be write-protected

  • underline (str: one of utils.underline or any other underline Excel supports) – The underline type

Changed in version 4.2.

Parameters:

border_type (str or set[str] or dict[str, str]) –

  • If provided a string (one of utils.borders or any other border type Excel supports): all borders will be set to that type.

  • If provided a set of strings (utils.border_locations or any other border location Excel supports): each provided border will be set to the default border type.

  • If provided a dict (from location, one of utils.border_locations or any other border location Excel supports) to border type (one of utils.borders or any other border type Excel supports): each provided border will be set to the provided border type.

New in version 1.2.

Parameters:
  • horizontal_alignment (str: one of utils.horizontal_alignments or any other horizontal alignment Excel supports) – Text’s horizontal alignment

  • vertical_alignment (str: one of utils.vertical_alignments or any other vertical alignment Excel supports) – Text’s vertical alignment

New in version 1.3.

Parameters:
  • wrap_text (bool) –

  • shrink_to_fit (bool) –

  • fill_pattern_type (str: one of utils.fill_pattern_types or any other fill pattern type Excel supports) – Cells’s fill pattern type

  • indent (int) –

  • comment_author (str) –

  • comment_text (str) –

  • text_rotation (int) – Integer in the range 0 - 180

New in version 4.0.

Parameters:

Note

For any of date_format, time_format and date_time_format to take effect, the value being styled must be an actual date/time/datetime object.

New in version 4.1.

Parameters:
  • strikethrough (bool) –

  • italic (bool) –

classmethod combine(*styles: Styler)[source]#

New in version 1.6.

Used to combine Styler objects. The right-most object has precedence. For example:

Styler.combine(Styler(bg_color='yellow', font_size=24), Styler(bg_color='blue'))

will return

Styler(bg_color='blue', font_size=24)
Parameters:

styles (list or tuple or set) – Iterable of Styler objects

Returns:

self

Return type:

Styler