Python-docx: How to set the table column different alignment?

Created on 30 Sep 2016  Â·  5Comments  Â·  Source: python-openxml/python-docx

Is it possible to set the table column to have different alignment? For example, the first column has alignment to the left but the second column has the alignment to the right. I have checked the document. It seems only table has the alignment attribute, not column. or is it possible to create a table style in word and set the table style like this? But I spent hours in word, still couldn't create such kind of table style. I really appreciate if you can help me resolve the issue. thanks

Ding

Most helpful comment

I have find a mathod ,you can try
cells[a].paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER

All 5 comments

are you Solved this question?

No, I haven't. I figured the table style has to be added in the word template, but I couldn't figure out how to add the table style in word.

I have find a mathod ,you can try
cells[a].paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER

You are awesome. This solved my problem! Thank you very much!

You want to use the docx.enum.text.WD_ALIGN_PARAGRAPH enumeration here rather than docx.enum.table.WD_TABLE_ALIGNMENT. It's the paragraph you're aligning, not the table cell.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssuzen picture ssuzen  Â·  6Comments

sskadit picture sskadit  Â·  4Comments

bendaojiu picture bendaojiu  Â·  5Comments

ronbarak picture ronbarak  Â·  3Comments

kociak picture kociak  Â·  5Comments