码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-07-06 20:11:20      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:文字   text   span   fonts   单元格   nts   bsp   style   cell   

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‘)

 

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

标签:文字   text   span   fonts   单元格   nts   bsp   style   cell   

原文地址:https://www.cnblogs.com/luckiness/p/13256275.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!