How to iterate over everything in a python-docx document?

前端 未结 2 753
温柔的废话
温柔的废话 2020-12-17 22:36

I am using python-docx to convert a Word docx to a custom HTML equivalent. The document that I need to convert has images and tables, but I haven\'t been able

2条回答
  •  眼角桃花
    2020-12-17 23:15

    Assuming doc is of type Document, then what you want to do is have 3 separate iterations:

    • One for the paragraphs, as you have in your code
    • One for the tables, via doc.tables
    • One for the shapes, via doc.inline_shapes

    The reason your code wasn't working was that paragraphs don't have references to the tables and or shapes within the document, as that is stored within the Document object.

    Here is the documentation for more info: python-docx

提交回复
热议问题