[Python] How to add the column headers on every page on python-docx?

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to print a Pandas data frame as .docx file on python. My problem is since the docx file will most of the time print more than 1 page, I want to have the column names of the data frame to be printed for every new page.

    Currently my code just prints the whole data frame as is:

    # add the header rows.
    for j in range(t01.shape[-1]):
    table.cell(0,j).text = t01.columns[j]

    # add the rest of the data frame
    for i in range(t01.shape[0]):
    for j in range(t01.shape[-1]):
    table.cell(i+1,j).text = str(t01.values[i,j])

    Continue reading...

Compartilhe esta Página