如何使用 python-docx 应用删除线

How to apply strike-through using python-docx

我的问题是,当我应用删除线或双删除线格式并保存文件时,它没有反映在输出文件中。

以下代码不起作用:

from docx import Document
document = Document()
p = document.add_paragraph()
p.add_run('Strike through the following text').strike = True
document.save('demo.docx')

这应该可以完成工作:

p.add_run('Strike through the following text').font.strike = True

strikefont 对象的 属性:docs

编辑

如果要更改多个字体属性,代码应为:

sentence = p.add_run('Strike through the following text')
sentence.font.strike = True
sentence.font.name = 'Comic Sans MS'