输入banner图图片脚本导航/分类

python读取word中的文本内容

Python可以利用python-docx模块处理word文档,处理方式是面向对象的。

安装 :在cmd命令行中输入 pip install python-docx

最后提示Successfully installed,表示成功地安装完成

代码:

# encoding=utf-8
import docx

#获取文档对象
file=docx.Document("E:\\pythoncode\\T11308010102mayuwen.docx")
print("段落数:"+str(len(file.paragraphs)))#段落数

#
输出每一段的内容 for para in file.paragraphs: print(para.text)

结果如图:

以上就是python读取word中的文本内容 的详细内容,更多请关注Gxl网其它相关文章!