任何人都可以帮助我在使用 python-docx 的 Python 中识别 .docx 文件中的段落是否包含带有删除线格式的文本(即它出现但被划掉),或者在开头有一个项目符号点?我正在尝试编写一个脚本来识别文档中的结构并解析内容。
到目前为止,我能够读取 .docx 文件并迭代段落,识别粗体段落。
from docx import Document
document = Document(r'C:\stuff\Document.docx')
for p in document.paragraphs:
print p.text
for run in p.runs:
if run.bold:
print 'BOLD ' + run.text
其余的暂时我不明白。
对于删除线,您可以像这样修改示例:
from docx import Document
document = Document(r'C:\stuff\Document.docx')
for p in document.paragraphs:
for run in p.runs:
if run.font.strike:
print "STRIKE: " + run.text
请参阅 API 文档了解Font http://python-docx.readthedocs.io/en/latest/api/text.html#font-objects对象以获取更多有趣的内容,您可以检查。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)