如何使用python docx应用strike through
我的问题是,当我应用贯穿或双重贯穿格式并保存文件时,它不会反映在输出文件中 以下代码不起作用:如何使用python docx应用strike through,python,python-docx,Python,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 t
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
strike
是font
对象的属性:
编辑
如果要更改多个字体属性,则代码应为:
sentence = p.add_run('Strike through the following text')
sentence.font.strike = True
sentence.font.name = 'Comic Sans MS'
谢谢!如果我需要给同一个文本另一个属性呢。例如:
p.add\u run(x).font.name='Comic Sans MS'
以及strike