Python操控Word--python-docx(2)-段落、字体设置

from docx import Document
from docx.shared import Inches, Cm, Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT, WD_LINE_SPACING
from docx.oxml.ns import qn

cur_dir = '...'
dirs = glob.glob(cur_dir+'\\*.jpg')

doc = Document()
for file in dirs:
    filename = file.split('_')
    paragraph1 = doc.add_paragraph()
    # 字号‘小五’对应磅值9
    # 字号‘五号’对应磅值10.5
    # 字号‘小四’对应磅值12
    # 字号‘四号’对应磅值14
    doc.styles['Normal'].font.size = Pt(12)
    doc.styles['Normal'].font.name = u'Times New Roman' #设置西文字体
    doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') #设置中文字体使用字体2->宋体

    # 空格=半个字符
    # 小5号----0.32cm 9pt,空格约为3.3磅
    # 5号----0.37cm 10.5pt,空格约为3.9磅
    # 小4号----0.42cm 12pt,空格约为4.4磅
    # 4号----0.49cm 14pt,空格约为5磅
    paragraph1.paragraph_format.first_line_indent = Pt(24)
    # ONE_POINT_FIVE&#
  • 1
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值