pythonodspyexcel

How to get a sheet name in an ODS file?


I saw that there are two libraries I can use: pyexcel_ods3 and pyexcel_ods. I tried to use

pyexcel_ods.Sheet("file.ods") 

and

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

but I got these errors:

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

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

Could you help me?


Solution

  • You probably made a mistake installing.

    Check you have both pyexcel and pyexcel-ods:

    pip install pyexcel pyexcel-ods
    

    Try the following code:

    from pyexcel import get_book
    
    sheet = get_book(file_name="file_example_ODS_10.ods")
    print(sheet)
    

    (you can get a valid example file here https://file-examples.com/index.php/sample-documents-download/sample-ods-download/)

    To get names:

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

    Result:

    ['Sheet1']
    

    Note that, in your example, you were trying to call get_book and Sheet directly on the pyexcel_ods module, while I only import pyexcel (and have the ods module installed) and that just works, pyexcel finds the module automatically when opening a .ods file.