远程协助
当前位置:首页>>文档中心>>服务器
标题:Ubuntu下使用python读取doc和docx文档的内容方法    日期:2019-03-24 13:01:00

读取docx文档

使用的包是python-docx

1. 安装python-docx包

sudo pip install python-docx 

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

#encoding:utf8 
import docx 
doc = docx.Document('test.docx') 
docText = '
'.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) 
下一篇:ubuntu18.04安装搜狗拼音的简易教程

联系我们
  • 客服热线:023-63522929(7 x 24h)
  • 在线客服:
  • 微信公众号 官方微博