网络编程
位置:首页>> 网络编程>> Python编程>> Ubuntu下使用python读取doc和docx文档的内容方法

Ubuntu下使用python读取doc和docx文档的内容方法

作者:Nicholas_Wong  发布时间:2021-04-09 03:42:30 

标签:python,doc,docx,读取

读取docx文档

使用的包是python-docx

1. 安装python-docx包


sudo pip install python-docx

2. 使用python-docx包读取数据


#encoding:utf8
import docx
doc = docx.Document('test.docx')
docText = '\n'.join([paragraph.text for paragraph in doc.paragraphs])
#print(docText)

python-docx这个包是不能处理doc文档的,要读取doc文档内容的话需要使用antiword这个工具。

读取doc文档

1. 到网站下载antiword。

2. 下载完毕之后解压,在解压得到的文件夹中依次运行make和make install命令。

3. 使用antiword读取doc文档内容


#encoding:utf8
import subprocess
word = 'test.doc'
output = subprocess.check_output(['antiword',word])
print(output)

来源:https://blog.csdn.net/Nicholas_Wong/article/details/71024969

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com