Page number python-docx

前端 未结 2 507
走了就别回头了
走了就别回头了 2020-12-01 19:32

I am trying to create a program in python that can find a specific word in a .docx file and return page number that it occurred on. So far, in looking through the python-do

2条回答
  •  余生分开走
    2020-12-01 19:39

    Using Python-docx: identify a page break in paragraph

    from docx import Document
    fn='1.doc'
    document = Document(fn)
    pn=1    
    import re
    for p in document.paragraphs:
        r=re.match('Chapter \d+',p.text)
        if r:
            print(r.group(),pn)
        for run in p.runs:
            if 'w:br' in run._element.xml and 'type="page"' in run._element.xml:
                pn+=1
                print('!!','='*50,pn)
    

提交回复
热议问题