如何使用python读取.odt?

时间:2021-09-27 15:46:03

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”库的python读取.odt,但它仍然不起作用。你能建议我如何使用python阅读.odt文件或给我一个简单的源代码。

Thank you

1 个解决方案

#1


0  

First install odfpy library then,

首先安装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!'

#1


0  

First install odfpy library then,

首先安装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!'