是否可以在Python中读取Word文件(.doc/.docx) [英] Is it possible to read Word files (.doc/.docx) in Python

查看:1407
本文介绍了是否可以在Python中读取Word文件(.doc/.docx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个验证工具;

I want to create a validation tool;

任何人都可以帮助我阅读Python中的.doc/.docx文档以搜索和比较文件内容.

Can any one help me read .doc/.docx documents in Python in order to search and compare the file contents.

推荐答案

是可以的. LibreOffice(至少)具有一个命令行选项,用于转换可以处理的文件.使用它可以将文件转换为文本.然后按照常规操作将文本文件加载到Python中.

Yes it is possible. LibreOffice (at least) has a command line option to convert files that works a treat. Use that to convert the file to text. Then load the text file into Python as per routine manoeuvres.

这在LibreOffice 4.2/Linux上对我有用:

This worked for me on LibreOffice 4.2 / Linux:

soffice --headless --convert-to txt:Text /path_to/document_to_convert.doc


我尝试了几种方法(包括odt2txt,反字词,zipfile,lpod,uno).上面的soffice命令是第一个简单且无错误的命令. 这个问题 ask.libreoffice.org 上将过滤器与soffice一起使用对我有帮助.


I've tried a few methods (including odt2txt, antiword, zipfile, lpod, uno). The above soffice command was the first that worked simply and without error. This question on using filters with soffice on ask.libreoffice.org helped me.

这篇关于是否可以在Python中读取Word文件(.doc/.docx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆