简体   繁体   English

如何使用 Python docx 遍历 docx 文件中的所有文本元素?

[英]How to iterate over all Text Elements in a docx file with Python docx?

I got an Word document and want to iterate over all Text elements.我有一个 Word 文档,想遍历所有 Text 元素。 The Strukture of the document is like:文件的结构如下:

Some text
   some other text

When i iterate over all Paragraphs i do only get "some text" but not "some other text" my interatein loks like this:当我遍历所有段落时,我只得到“一些文本”而不​​是“一些其他文本”,我的交互看起来像这样:

for para in document.paragraphs:
print(para .text)

i dident see the hole text because document.paragraphs does not show all text elements by design.我没有看到孔文本,因为document.paragraphs没有按设计显示所有文本元素。 In my word document was the missed text in an table so i hade to iterate throug the tables too在我的word文档中是表格中丢失的文本,所以我也不得不遍历表格

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

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