Formatting Excel (xlsx and xls only) files with the file connector is based on polars write_excel function which uses XlsxWriter to write files. For the sake of not rewriting polars and XlsxWriter documentation, this will be kept to a few short examples. Just know, that anything that is possible with polars is possible with the formatting parameter.
Note: This does not work in the WranglesXL add-in.
This allows users to format the header row of their file.
write:
- file:
name: tests/temp/format_data.xlsx
formatting:
header_format:
font_name: Rastanty Cortez
font_size: 25
bold: true
underline: true

Format columns individually.
write:
- file:
name: tests/temp/format_data.xlsx
formatting:
column_formats:
col1:
font_name: Ravie
font_size: 30
bg_color: '#04260D'
font_color: '#5AEC80'
col2:
font_name: OCRB
font_size: 15
bg_color: '#2C0224'
font_color: '#F73BD3'

Conditional formatting allows users to format columns based on conditions. This is overwritten by column_formats if they are both used on the same column, and only one condition can be used at a time.
| col1 | col2 |
|---|---|
| 123 | x |
| a | y |
| b | y |
| c | y |
| d | x |
write:
- file:
name: tests/temp/format_data.xlsx
formatting:
conditional_formats:
col1:
type: text
criteria: not containing
value: '123'
format:
bg_color: '#04260D'
font_color: '#5AEC80'
col2:
type: text
criteria: containing
value: x
format:
bg_color: '#2C0224'
font_color: '#F73BD3'

Note: column_formats and header_format can easily be combined as well as conditional_formats and header_format, but it is not advised to use conditional and column formats on the same columns.