如何使用python读取.odt? [英] How to read .odt using python?

查看:69
本文介绍了如何使用python读取.odt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用带有odfpy"库的 python 读取 .odt,但它仍然不起作用.你能告诉我如何使用 python 读取 .odt 文件或给我一个简单的源代码.

I tried to read .odt using python with "odfpy" library, but it still doesn't work. Could you suggest me how to read .odt file using python or give me a simple source code.

谢谢

推荐答案

首先安装 odfpy 库然后,

In [21]: from odf import text, teletype
    ...: from odf.opendocument import load
    ...: 
    ...: textdoc = load("your.odt")
    ...: allparas = textdoc.getElementsByType(text.P)
    ...: teletype.extractText(allparas[0])
    ...: 
Out[21]: 'Hello World!'

这篇关于如何使用python读取.odt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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