最新下载
热门教程
- 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)
相关文章
- 奥比岛梦想国度卡死闪退有哪些解决方法 04-30
- DNF手游骨戒在哪个位置 04-30
- 回望羊驼:当利空成为短暂的财富密码 04-30
- 为什么每个 Web3 项目都逃不过 DEX? 04-30
- HashKey Exchange 虚拟资产保险覆盖规模登顶全球第一 04-30
- HTX DeepThink:冲上$95,000后,等待比特币的是什么? 04-30