最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Ubuntu下使用python读取doc和docx文档的内容方法
时间:2022-06-30 19:09:54 编辑:袖梨 来源:一聚教程网
读取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)
相关文章
- 我的世界棕色染料怎么获得 棕色染料用途合成表一览 09-15
- 我的世界墨囊怎么获得 墨囊用途合成表一览 09-15
- 超级机器人大战Y魔女新娘与天使怎么过 特殊剧情关卡攻略 09-15
- 超级机器人大战Y漂流异邦人怎么过 特殊关卡通关攻略 09-15
- 七日世界肥料怎么获得-肥料获取方法 09-15
- 超级机器人大战Y受托的勇者们怎么过 关键剧情关卡攻略 09-15