如何在ODS文件中获取图纸名称?

2024-09-30 14:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我看到有两个库可以使用:pyexcel_ods3pyexcel_ods。 我试着用

pyexcel_ods.Sheet("file.ods") 

pyexcel_ods.get_book(file_name="file.ods") 

但我犯了以下错误:

AttributeError: module 'pyexcel_ods' has no attribute 'Sheet'

AttributeError: module 'pyexcel_ods' has no attribute 'get_book'

你能帮我吗


Tags: nonameget错误attributepyexcelodsfile
1条回答
网友
1楼 · 发布于 2024-09-30 14:21:20

您可能安装时出错了

检查您是否同时拥有pyexcelpyexcel-ods

pip install pyexcel pyexcel-ods

请尝试以下代码:

from pyexcel import get_book

sheet = get_book(file_name="file_example_ODS_10.ods")
print(sheet)

(您可以在此处获取有效的示例文件https://file-examples.com/index.php/sample-documents-download/sample-ods-download/

要获取名称,请执行以下操作:

from pyexcel import get_book

sheet = get_book(file_name="file_example_ODS_10.ods")
print(sheet.sheet_names())

结果:

['Sheet1']

请注意,在您的示例中,您试图直接在pyexcel_ods模块上调用get_bookSheet,而我只导入pyexcel(并安装了ods模块),这样就可以了,pyexcel在打开.ods文件时会自动找到该模块

相关问题 更多 >