Dzwebs.Net

撰写电脑技术杂文十余年

python-docx删除所有段落清空所有段落内容的方法

Admin | 2022-2-8 10:06:50 | 被阅次数 | 4641

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  python-docx删除所有段落清空所有段落内容的方法如下,都使用代码进行操作。

  一、引入

  from docx import Document
  from docx.shared import Inches

  如果没有安装python-docx,求先安装,否则不能正确引入,安装方法就简单了嘛,使用 pip install python-docx 就可以了。

  然后,再打开WORD

  document = Document('TempPaper.docx')#打开WORD

  二、清空每一个段落的内容

  for p in range(len(document.paragraphs)):
    document.paragraphs[p].clear()

  三、删除所有段落

  for paragraph in document.paragraphs:
                p=paragraph._element
                p.getparent().remove(p)
                paragraph._p=paragraph._element=None


该杂文来自: 最新技术

上一篇:flask下载文件错误提示:The requested URL was n

下一篇:python使用win32com在word中插入图片插入段落

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计