我试图在python中创建一个程序,可以在.docx文件中找到特定的单词并返回它发生的页码.到目前为止,在查看python-docx文档时,我一直无法找到如何访问页码或甚至是数字所在的页脚.有没有办法使用python-docx或甚至只是python?或者如果没有,最好的方法是什么?
我正在尝试使用 docx-python 库在文档中间添加分页符。
似乎在添加分页符时,分页符被添加到文档的末尾。有没有一种方法可以将分页符添加到特定位置?
这是我目前的代码。
from docx import Document
from docx.shared import Inches
demo='gm.docx'
document = Document(docx=demo)
for paragraph in document.paragraphs:
if 'PUB' in paragraph.text:
document.add_page_break()
document.save('gm.docx')
Run Code Online (Sandbox Code Playgroud)