Home > Backend Development > Python Tutorial > python reads text content in word

python reads text content in word

不言
Release: 2018-04-09 17:23:28
Original
9832 people have browsed it


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)
Copy after login

结果如图:



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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template