How to read .odt using python? [closed]

我的未来我决定 提交于 2021-02-07 22:43:14

问题


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.

Thank you


回答1:


First install odfpy library then,

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!'


来源:https://stackoverflow.com/questions/51054770/how-to-read-odt-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!