如何设置表格中单元格的宽度?到目前为止,我得到了以下内容:
from docx import Document
from docx.shared import Cm, Inches
document = Document()
table = document.add_table(rows=2, cols=2)
table.style = 'TableGrid' #single lines in all cells
table.autofit = False
col = table.columns[0]
col.width=Inches(0.5)
#col.width=Cm(1.0)
#col.width=360000 #=1cm
document.save('test.docx')
无论我设置什么数字或单位,col.width 的宽度都不会改变。
for cell, width in zip(row.cells, (Inches(1), Inches(2), Inches(1.5))): cell.width = width
- altendkyfor idx, col in enumerate(table.columns): col.width = widths[idx]
)。 - Garrettfor cell in table.columns[0].cells
- Rob Irwin