How to apply cell sytling?
Style: Add "style"-ing to individual dataframe exports
In writer.to_excel(df, ..., style={})
you can define specific styling kwargs for that specific table.
The style dictionary syntax is:
dictionary key: reference the column, row, or cell |
dictionary value: provide formatting specs |
---|---|
Options:
|
Options:
|
Examples: (showcasing the many different styling options)
style = {'C3:D10': {'font__size': 20, 'numberformat': '#,##0', 'font__italic'=True}, 'employees:customers': {'numberformat': '#,##0'}}
MY_CUSTOM_WARNING_STYLE = {'font__bold': True, 'text__color': 'ff0000', 'font__size': 20}
MY_CUSTOM_DATE_STYLE = {'numberformat': 'yyyy-mm-dd'}
style = {
'1': MY_CUSTOM_WARNING_STYLE,
'2:5': {'font__size': 20},
'B3:G10': ['bg_light_blue', 'num_fmt_pct'],
'A1': {**MY_CUSTOM_WARNING_STYLE, **MY_CUSTOM_DATE_STYLE}
}
Theme: Set "theme" for entire excel file
In ExcelWriter(..., theme='elegant_blue')
you can define the base theme that will be applied to your entire Excel file.
You can pass either:
- a theme name like 'elegant_blue',
- or your personal .yml-theme-file path (syntax example here)