I know this is a repeated question but those answers are not works for me. I have a word file which consist one table now i want that table as a output of my python program. I'm using python 3.6 and i have installed python -docx as well. Here is my code for the data extraction
from docx.api import Document
document = Document('test_word.docx')
table = document.tables[0]
data = []
keys = None
for i, row in enumerate(table.rows):
text = (cell.text for cell in row.cells)
if i == 0:
keys = tuple(text)
continue
row_data = dict(zip(keys, text))
data.append(row_data)
print (data)
I want the result what exactly looks in the word docx file. Thanks in advance
Your code works fine for me. How about inserting it into a dataframe?
How can i display particular row and column in that table? We can extract rows and cols based on index with iloc
and so on...
However, if your columns have names (in this case it is numbers) you can do it like this:
prints, which is how the table looks like in my sample doc.