word文档第b页

2024-06-09 07:21:08 发布

您现在位置: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')

Tags: 方法infrom文档import密码demodocument