I used this code:
# open a document
doc = docx.Document()
# add a table to the end and create a reference variable
# extra row is so we can add the header row
t = doc.add_table(df.shape[0]+1, df.shape[1])
t.allow_autofit = True
t.style = 'TableGrid'
t.alignment=WD_TABLE_ALIGNMENT.CENTER
Where df
is some pandas
DataFrame
. But the columns are not auto-fitting.