How can I read and process contents of every cell of a table in a DOCX file?
I am using Python 3.2 on Windows 7 and PyWin32 to access the MS-Word Document.
I am a beginner so I don't know proper way to reach to table cells. So far I have just done this:
import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = False
doc = word.Documents.Open("MyDocument")
Jumping in rather late in life, but thought I'd put this out anyway: Now (2015), you can use the pretty neat doc python library: https://python-docx.readthedocs.org/en/latest/. And then:
from docx import Document
wordDoc = Document('<path to docx file>')
for table in wordDoc.tables:
for row in table.rows:
for cell in row.cells:
print cell.text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With