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

2024-05-17 05:40:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我用了这个代码:

# 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是一些pandasDataFrame。但这些柱子不是自动装配的。在

enter image description here


Tags: andtheto代码adddfdoctable