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')
python-docx设置标题颜色
于 2022-02-15 09:59:35 首次发布