[Python] Python-docx, how to set cell width in tables?

Discussão em 'Python' iniciado por Stack, Novembro 27, 2025.

  1. Stack

    Stack Membro Participativo

    How to set cell width in tables?, so far I got:

    from docx import Document
    from docx.shared import Cm, Inches

    document = Document()
    table = document.add_table(rows=2, cols=2)
    table.style = 'TableGrid' #single lines in all cells
    table.autofit = False

    col = table.columns[0]
    col.width=Inches(0.5)
    #col.width=Cm(1.0)
    #col.width=360000 #=1cm

    document.save('test.docx')


    No mater what number or units I set in col.width, its width does not change.

    Continue reading...

Compartilhe esta Página