Python Docx:如何将列宽设置为“自动适应内容”

use*_*390 5 python docx pandas python-docx

我使用了这段代码:

# 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
Run Code Online (Sandbox Code Playgroud)

哪里df有一些pandas DataFrame。但列不能自动调整。

在此输入图像描述