python线条加粗_python docx 设置word表格边框(颜色/线型/粗细)

曾经在网上苦苦寻找过python docx对word表格边框的设置,一直没有,现在终于有了,包括边框颜色、线型、宽度粗细的设置,直接用这个函数set_cell_border就行了(附加office的参数参考),这是对单个单元格(cell)的上下左右四个边框进行设置的:

注意要提前安装python-docx模块呦,pip安装命令:pip install python-docx!

from docx.oxml import OxmlElement

from docx.oxml.ns import qn

def set_cell_border(cell, **kwargs):

"""

Set cell`s border

Usage:

set_cell_border(

cell,

top={"sz": 12, "val": "single", "color": "#FF0000", "space": "0"},

bottom={"sz": 12, "color": "#00FF00", "val": "single"},

left={"sz": 24, "val": "dashed", "shadow": "true"},

right={"sz": 12, "val": "dashed"},

)

"""

tc = cell._tc

你可能感兴趣的:(python线条加粗)