from docx import Document
from docx.shared import Pt,RGBColor
from docx.oxml.ns import qn
from docx.enum.text import WD_ALIGN_PARAGRAPH
scrdocx = Document('2.docx')
for paragraph in scrdocx.paragraphs:
# lastp = scrdocx.paragraphs[len(scrdocx.paragraphs)-1] #清除最后一段
# lastp.clear()
for run in paragraph.runs:
run.font.bold = True #黑体
run.font.italic = False #斜体
run.font.underline = False #下划线
run.font.strike = False #删除线
run.font.shadow = False #阴影
run.font.size = Pt(16) #字体大小
run.font.color.rgb = RGBColor(0,0,0) #字体颜色
run.font.name = '仿宋_GB2312' #字体
r = run._element.rPr.rFonts #中文字体
r.set(qn('w:eastAsia'),'仿宋_GB2312')
paragraph.alignment = WD_ALIGN_PARAGRAPH.LEFT #对齐方式
paragraph.paragraph_format.line_spacing = 2.0 #用浮点数,表示两倍行间距
paragraph.paragraph_format.space_before = Pt(12) #表示12磅
paragraph.paragraph_format.space_after = Pt(28)
scrdocx.save('2.docx')
字号‘八号’对应磅值5
字号‘七号’对应磅值5.5
字号‘小六’对应磅值6.5
字号‘六号’对应磅值7.5
字号‘小五’对应磅值9
字号‘五号’对应磅值10.5
字号‘小四’对应磅值12
字号‘四号’对应磅值14
字号‘小三’对应磅值15
字号‘三号’对应磅值16
字号‘小二’对应磅值18
字号‘二号’对应磅值22
字号‘小一’对应磅值24
字号‘一号’对应磅值26
字号‘小初’对应磅值36
字号‘初号’对应磅值42