Skip to content

Styling of column and row headers not reflected when saving to excel.  #25185

Closed
@saihari

Description

@saihari

Following is the code I used to style the headers of both rows and columns and then saving the stylized data frame to an excel file.

df = pd.DataFrame([1000000.0, 1000000.0], index=pd.bdate_range('2017-08-01', '2017-08-02'))

df.index = df.index.strftime("%Y-%m-%d")
styler = df.style
styler.set_table_styles(
# select the table header with th and set it right align
    [dict(selector="th", props=[("text-align", "right"),('color','green')])]   
)
styler.to_excel('styled.xlsx', engine='openpyxl')

Problem description

I am trying to stylize the headers of a data frame and then save that data frame to an excel file, but I am unable to see the stylized effects inside the excel file.

Output of Jupyter Notebook

image

Output in excel file

image

Expected Output

image

Pandas Version: '0.24.1'

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIO Excelread_excel, to_excelStylerconditional formatting using DataFrame.style

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions