系统教程
您现在的位置是:首页>服务器系统>Ubuntu系统内容

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

时间:2018-04-28 出处:未知复制分享人气(次) 【

读取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(http://www.winfield.demon.nl/#Programmer)。
2.下载完毕之后解压,在解压得到的文件夹中一次运行make和make install命令。
3.使用antiword读取doc文档内容
#encoding:utf8  
import subprocess  
word = 'test.doc'  
output = subprocess.check_output(['antiword',word])  
print(output)
    最新资讯
    热门内容
    小米移动电源能为iPad mini充几次电