700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何使用python-docx库设置表格单元格的边距(How to set cell margins of tables using python docx)

如何使用python-docx库设置表格单元格的边距(How to set cell margins of tables using python docx)

时间:2018-11-12 17:09:18

相关推荐

如何使用python-docx库设置表格单元格的边距(How to set cell margins of tables using python docx)

1.插入表格后,目前python-docx没有官方方法将单元格边距设置成自己想要的距离。

2.下面代码可实现调整单元格边距

from docx.table import _Celldef set_cell_margins(cell: _Cell, **kwargs):"""cell: actual cell instance you want to modifyusage: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: /WPtableCellMargins.php"""tc = cell._tctcPr = 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)

2.更多openxml tags可点击/WPtableCellMargins.php

Elements:

Attributes:

The attributes for the above table cell margin elements are:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。