python-docx表格设置实线_python docx加入表格 在表格中加图,设置框线

from docx import Document #pip3 install python-docx

from docx.shared import Inches #英寸

import os

#from docx import Document

from docx.shared import Pt

from docx.enum.text import WD_PARAGRAPH_ALIGNMENT

from docx.shared import Cm #厘米

from docx.shared import RGBColor

from docx.enum.table import WD_TABLE_ALIGNMENT #表格排列方式

from docx.enum.table import WD_ALIGN_VERTICAL

from docx.enum.text import WD_ALIGN_PARAGRAPH

from natsort import natsorted #自然排序

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

tcPr = tc.get_or_add_tcPr()

# check for tag existnace, if none found, then create one

tcBorders = tcPr.first_child_found_in("w:tcBorders")

if tcBorders is None:

tcBorders = OxmlElement(&#

你可能感兴趣的:(python-docx表格设置实线_python docx加入表格 在表格中加图,设置框线)