Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python docx应用strike through_Python_Python Docx - Fatal编程技术网

如何使用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