1.安装odfpy模块
pip install odfpy
2.操作代码
from odf import text, teletype
from odf.opendocument import load
def test_ods():
loc = '/home/heshiyang/Desktop/test.ods'
textdoc = load(loc)
allparas = textdoc.getElementsByType(text.P)
print(teletype.extractText(allparas[0]), teletype.extractText(allparas[1]), teletype.extractText(allparas[2]))
print(teletype.extractText(allparas[3]), teletype.extractText(allparas[4]), teletype.extractText(allparas[5]))
print(teletype.extractText(allparas[6]), teletype.extractText(allparas[7]), teletype.extractText(allparas[8]))
print(teletype.extractText(allparas[9]), teletype.extractText(allparas[10]), teletype.extractText(allparas[11]))
#没有的数据打印出来就是乱码
print(teletype.extractText(allparas[12]))
if __name__ == '__main__':
print('===============begin=================')
test_ods()
print('===============end=================')
文件内容:
读取结果: