python-docx设置标题颜色

from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Inches
from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.shared import Inches
from docx.shared import Pt #磅数
from docx.oxml.ns import qn #中文格式
from docx.shared import RGBColor#设置字体

document = Document()
T1_1=document.add_heading('', level=1)
run_T1_1 = T1_1.add_run('一级标题')
# 设置西体格式
run_T1_1.font.name = '宋体'
run_T1_1.element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')
# 设置标题颜色
run_T1_1.font.color.rgb = RGBColor(0,0,0)
run_T1_1.font.size = Pt(22)
run_T1_1.font.bold = True

document.save('demo_x.docx')
posted @ 2022-11-21 21:20  那酒不要留  阅读(210)  评论(0编辑  收藏  举报
/* 雪花特效 */