Python:按顺序读取Word文档

问题描述 投票:0回答:1

第一次使用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 docx word paragraph
1个回答
0
投票

取决于您是否可以访问代码中的订单信息。

© www.soinside.com 2019 - 2024. All rights reserved.