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')
作者:那酒不要留
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!知识源于分享!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!