【发布时间】:2020-08-04 15:20:42
【问题描述】:
第一次在这里使用python。我正在尝试浏览一个包含段落和表格的word文档。我已经弄清楚如何使用以下代码浏览文档中的所有段落和文档中的所有表格:
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
print(str(paragraph.text))
for i in doc.paragraphs:
splitstring = i.text.split(" ", 1)
print(splitstring[0])
但我正试图找出一种方法来按顺序浏览文档,就像阅读它的任何人一样。因此,如果我们有一个包含以下内容的文档:
Paragraph 1
Paragraph 2
Table 1
Paragraph 3
Table 2
Paragraph 4
它会按顺序读取它们。我想这样做的原因取决于表格后面的段落,我想对其进行不同的操作。
【问题讨论】:
标签: python python-3.x ms-word docx paragraph