downloader downloader - 1 year ago 317
Python Question

python-docx center table content

I've just started using python-docx and I'm trying to center the contents of my table. I have:

table = document.add_table(rows=1, cols=1)
tableHeader = table.rows[0].cells
tableHeader[0].text = 'test'
row_cells = table.add_row().cells
row_cells[0].text = 'example' = 'MediumGrid3'

which outputs a table with the header
and the text

I thought
table.alignment = 1
would work, but it does nothing.

So how do I align all the text to the center?

Answer Source

The setting you're asking about isn't yet supported in python-docx.

If you add an issue for it, perhaps titled: "feature: Table.alignment", to the GitHub issues list, we'll add it to the backlog.

If you haven't come across it yet, you can find the documentation for python-docx here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download