要删除文档中的 sectPr 和 pgBorders,您可以使用 python-docx 库中的以下代码:

from docx import Document
from docx.oxml import OxmlElement
from docx.oxml.ns import qn

# 打开文档
doc = Document('your_document.docx')

# 删除 sectPr
sectPr = doc._element.xpath('//w:sectPr')
for element in sectPr:
    element.getparent().remove(element)

# 删除 pgBorders
for section in doc.sections:
    section._element.clear_content()

# 保存文档
doc.save('your_document_without_sectPr_pgBorders.docx')

此代码将删除文档中的所有 sectPr 元素和每个节的 pgBorders 元素。最后,它将保存一个不包含这些元素的新文档

python-docx 删除文档sectPr pgBorders

原文地址: https://www.cveoy.top/t/topic/fX3s 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录