I want to extract all the tables in a document, process them, and then paste the new tables and the text of the document into another document in the original order. But in Python-docx, paragraphs and tables have no order-relation at all, what should I do?
from docx import Document
def address_of_table(doc):
table_num = 0
for table in doc.tables:
table_num += 1
address_list = [int for _ in range(table_num)]
para_index = 0
tab_index = 0
for paragraph in doc.paragraphs:
para_index += 1
#………
#………
for table in doc.tables:
address_list[tab_index] = para_index
tab_index += 1
return address_list
New contributor
Sword Lina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.