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

查看:35
本文介绍了是否可以在 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、antiword、zipfile、lpod、uno).上面的 soffice 命令是第一个简单且没有错误的命令.这个问题ask.libreoffice.orgsoffice 使用过滤器> 帮了我.


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天全站免登陆