python生成的word表格设置内容居中 python生成的word表格设置内容内容默认左对齐,生成的表格不美观可以使用一下代码将内容居中 需要导入的库 from docx.enum.table import WD_TABLE_ALIGNMENT 将单元格内容设置居中 for r in range(6):#循环将每一行,每一列都设置为居中 for c in range(8): table.cell(r, c).paragraphs[0].paragraph_format.alignment = WD_TABLE_ALIGNMENT.CENTER 这样就可以将word表格中的内容居中了。