How to read contents of an Table in MS-Word file Using Python?

后端 未结 3 1662
栀梦
栀梦 2020-11-27 14:11

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

3条回答
  •  庸人自扰
    2020-11-27 15:04

    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('')
    
    for table in wordDoc.tables:
        for row in table.rows:
            for cell in row.cells:
                print cell.text
    

提交回复
热议问题