I have .docx file with many paragraphs and tables like:
- par1
- table1
- table2
- table3
par2
- table1
- table2
2.1 par21
- table1
- table2
I need to iterate all objects and make dictionary, maybe in json format like:
{par1: [table1, table2, table3], par2[table1,table2, {par21: [table1,table2]} ] }
from docx.api import Document
filename = 'test.docx'
document = Document(docx=filename)
for table in document.tables:
print table
for paragraph in document.paragraphs:
print paragraph.text
How can I relate each paragraph and tables?
Can you suggest something ?