|
设置表格所有单元格的四个边为0.5磅,黑色,实线 可以使用返回值www.lu0.com,也可以不使用
def 设置表格网格线为黑色实线(table_object: object ):
kwargs = {
top :{ sz : 4 , val : single , color : #000000 },
bottom :{ sz : 4 , val : single , color : #000000 },
left :{ sz : 4 , val : single , color : #000000 },
right :{ sz : 4 , val : single , color : #000000 },
insideV :{ sz : 4 , val : single , color : #000000 },
insideH :{ sz : 4 , val : single , color : #000000 }
}
borders = docx.oxml.OxmlElement( w:tblBorders )
for tag in ( bottom , top , left , right , insideV , insideH ):
edge_data = kwargs.get(tag)
if edge_data:
any_border = docx.oxml.OxmlElement(f w:{tag} )
for key in [ sz , val , color , space , shadow ]:
if key in edge_data:
any_border. set (docx.oxml.ns.qn(f w:{key} ), str (edge_data[key]))
borders.append(any_border)
table_object._tbl.tblPr.append(borders)
return table_object
设置标题样式
def 设置标题样式为黑色宋体(heading_object: object ):
heading_object.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.LEFT #左对齐
for run in heading_object.runs:
run.font.name = u 宋体 #设置为宋体
#run._element.rPr.rFonts.set(qn(w:eastAsia), u宋体)#设置为宋体,和上边的一起使用
run.font.color.rgb = docx.shared.RGBColor( 0 , 0 , 0 ) #设置颜色为黑色 |