How do I extract data from a doc/docx file using Python

后端 未结 4 1860
[愿得一人]
[愿得一人] 2020-12-08 23:57

I know there are similar questions out there, but I couldn\'t find something that would answer my prayers. What I need is a way to access certain data from MS-Word files and

4条回答
  •  再見小時候
    2020-12-09 00:50

    To search in a document with python-docx

    # Import the module
    from docx import *
    
    # Open the .docx file
    document = opendocx('A document.docx')
    
    # Search returns true if found    
    search(document,'your search string')
    

    You also have a function to get the text of a document:

    https://github.com/mikemaccana/python-docx/blob/master/docx.py#L910

    # Import the module
    from docx import *
    
    # Open the .docx file
    document = opendocx('A document.docx')
    fullText=getdocumenttext(document)
    

    Using https://github.com/mikemaccana/python-docx

提交回复
热议问题