【问题标题】:How can I change letters’ color? [duplicate]如何更改字母的颜色? [复制]
【发布时间】:2018-08-16 16:50:55
【问题描述】:

我想在docx中写字母。我写了代码,

from docx import Document

document = Document()

document.add_heading("TITLE", 1)

document.save("test.docx")

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

【问题讨论】:

    标签: python python-docx


    【解决方案1】:

    可能重复:

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

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

    您需要使用字体属性。

    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 文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 2014-11-26
      • 1970-01-01
      • 2023-04-01
      • 2021-09-06
      • 2014-10-12
      • 2010-10-19
      相关资源
      最近更新 更多