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中的文本内容_第1张图片

你可能感兴趣的:(python读取word中的文本内容)