给表格中的文字设置字体以及设置表格样式

from  docx import  Document
from  docx.oxml.ns  import  qn  #中文字体

w=Document()
table=w.add_table(3,3,style='Medium Grid 1 Accent 1')
table_head=table.rows[0].cells
table_head[0].text='姓名'
table_head[1].text='性别'
table_head[2].text='年龄'

#将表格中所有的单元格修改字体

for  row in table.rows:
    for  cell in row.cells:
        for paragraph in cell.paragraphs:
            for run in paragraph.runs:
                run.font.name='Arial'   #英文字体设置
                run._element.rPr.rFonts.set(qn('w:eastAsia'),'微软雅黑')
                
w.save(r'D:word练习给表格设置样式及修改字体.docx')
原文地址:https://www.cnblogs.com/luckiness/p/13256275.html