简体   繁体   English

使用 python 从表 in.docx 文件中获取文本

[英]Get text from table in .docx file using python

I need to get full text of document as python string.我需要将文档的全文作为 python 字符串。 So, I use docx library:所以,我使用 docx 库:

doc = docx.Document(user_file)
fullText = []
for para in doc.paragraphs:
   fullText.append(para.text)
text = '\n'.join(fullText)

It works, but ignore text in tables.它有效,但忽略表格中的文本。 How should I get data from tables?我应该如何从表中获取数据? Maybe there is any way to clear tags or somehow prepare document?也许有什么方法可以清除标签或以某种方式准备文件? Thanks in advance!提前致谢!

doc.tables returns a list of Table instances corresponding to the tables in the document, in document order. doc.tables按文档顺序返回与文档中的表对应的 Table 实例列表。 Note that only tables appearing at the top level of the document appear in this list;请注意,只有出现在文档顶层的表格才会出现在此列表中; a table nested inside a table cell does not appear.不会出现嵌套在表格单元格内的表格。 A table within revision marks such as <w:ins> or <w:del> will also not appear in the list. <w:ins> 或 <w:del> 等修订标记内的表格也不会出现在列表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM