【发布时间】:2018-08-13 02:26:02
【问题描述】:
我想使用 python 从 .docx 文件中的表中提取文本以进行进一步分析。我使用以下代码:
document = Document(path_to_your_docx)
tables = document.tables
for table in tables:
for row in table.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
print(paragraph.text)
但是这个表格的单元格中似乎还有另一个“表格”,所以我无法提取这部分(如附图所示)。当我使用上面的代码时,我无法获取“是/否”文本。
我也尝试像在表格中一样遍历单元格,但我收到单元格没有表格属性的错误。有什么建议吗?
谢谢。
【问题讨论】:
-
请勿粘贴代码截图。
标签: python docx python-docx