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)
结果如图:
The above is the detailed content of python reads text content in word. For more information, please follow other related articles on the PHP Chinese website!