据我了解,您只能更改表格的单元格宽度。
最佳答案
我使用此代码段修改单元格的边距
def set_cell_margins(cell: _Cell, **kwargs):
"""
cell: actual cell instance you want to modify
usage:
set_cell_margins(cell, top=50, start=50, bottom=50, end=50)
provided values are in twentieths of a point (1/1440 of an inch).
read more here: http://officeopenxml.com/WPtableCellMargins.php
"""
tc = cell._tc
tcPr = tc.get_or_add_tcPr()
tcMar = OxmlElement('w:tcMar')
for m in [
"top",
"start",
"bottom",
"end",
]:
if m in kwargs:
node = OxmlElement("w:{}".format(m))
node.set(qn('w:w'), str(kwargs.get(m)))
node.set(qn('w:type'), 'dxa')
tcMar.append(node)
tcPr.append(tcMar)
您可以在此处http://officeopenxml.com/WPtableCellMargins.php阅读更多有关openxml标记的信息。
关于python - 如何使用python docx在ms word中设置表格的单元格边距,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51060431/