如何更改字母的颜色?

时间:2018-08-16 08:11:14

标签: python python-docx

我想用docx写字母。我写了代码,

from docx import Document

document = Document()

document.add_heading("TITLE", 1)

document.save("test.docx")

但是当我运行代码时,TITLE的字母是蓝色。我想在TITLE中添加黑色。我在docx文档中搜索了它的方式,但找不到它,该怎么办?< / p>

1 个答案:

答案 0 :(得分:0)

可能的副本:

Write text in particular font color in MS word using python-docx

Using docx python library, how to apply color and font size simultaneously

您将需要使用font属性。

from docx import Document

document = Document()

run = document.add_heading().add_run("TITLE")

font = run.font
font.color.rgb = RGBColor(0,0,0)

document.save("test.docx")

请参阅python-docx文档。