[Python] Pandas df write to Excel template with prepared styles

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have DataFrame df.

    I have Excel file template_with_styles.xlsx in which there is a color table ready.

    I want to write df to a template.

    from openpyxl.utils.dataframe import dataframe_to_rows

    wb = load_workbook('template_with_styles.xlsx')
    ws = wb.active
    for r in dataframe_to_rows(df, index=None, header=True):
    ws.append(r)
    wb.save('my.xlsx')


    As a result, I get: first comes my table with styles, and below is the data without styles.

    How can I write DataFrame to a Ecxel using a prepared template?

    Continue reading...

Compartilhe esta Página