0

I have a table in a word document and I want to extract the information from it using Python. I am able to access tables from word documents using the code below, however, this time the table is in a text box.

How can I access a table if it is in a text box?

import win32com.client as win32
word.Documents.Open(filename) ###open word file
doc = word.ActiveDocument  
table = doc.Tables(1)

where table is the table, and I can access its information etc.

Kind regards, Nima

1 Answer 1

3

I wrote a solution using another python package docx2python.

from docx2python import docx2python
doc = docx2python(word_document_path)
doc_body = doc.body
table = doc_body[table_number]
table = pd.DataFrame(table)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.