Я использовал этот код:
# 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
Где df
- это pandas
DataFrame
.Но столбцы не устанавливаются автоматически.
