pyexcel-ezodf: OpenDocumentFormat files
pyexcel-ezodf is a Python package that serves as a pyexcel plugin, enabling it to read from and write to OpenDocumentFormat (ODF) files, commonly used by LibreOffice or OpenOffice. It provides an easy way to manipulate tabular data within ODS documents through the familiar pyexcel API. The current version is 0.3.4, with releases typically being maintenance updates rather than frequent feature additions.
Common errors
-
ModuleNotFoundError: No module named 'pyexcel'
cause The core `pyexcel` library, which `pyexcel-ezodf` extends, is not installed.fixInstall `pyexcel`: `pip install pyexcel` or simply `pip install pyexcel-ezodf` (which includes `pyexcel` as a dependency). -
pyexcel.exceptions.NoReaderFound: No suitable reader found for 'your_file.ods'
cause `pyexcel-ezodf` is not installed, so `pyexcel` does not have the capability to process OpenDocument Spreadsheet (.ods) files.fixInstall the `pyexcel-ezodf` plugin: `pip install pyexcel-ezodf`. -
ModuleNotFoundError: No module named 'ezodf'
cause The underlying `ezodf` library, a dependency of `pyexcel-ezodf`, is not installed or accessible.fixInstall `ezodf`: `pip install ezodf` or ensure `pyexcel-ezodf` was installed correctly which should pull its dependencies.
Warnings
- gotcha The underlying `ezodf` library, and consequently `pyexcel-ezodf`, loads the entire ODS document into memory. This can lead to high memory consumption and slow performance when working with very large ODS files.
- gotcha `pyexcel-ezodf` is a plugin designed to extend `pyexcel`. If you encounter errors like `pyexcel.exceptions.NoReaderFound` or the ODS file is not handled as expected, it might indicate that either `pyexcel` itself is not installed, or `pyexcel-ezodf`'s dependencies (`ezodf`) are missing.
Install
-
pip install pyexcel-ezodf
Imports
- pyexcel
import pyexcel
- get_data
from pyexcel_ezodf import get_data, save_data
Quickstart
import pyexcel
import os
# Data to write to an ODS file
data = [
["Item", "Quantity", "Price"],
["Apple", 10, 1.5],
["Banana", 5, 0.75],
["Orange", 8, 1.2]
]
# Define a temporary file name
file_name = "example.ods"
try:
# Save the data to an ODS file
pyexcel.save_as(array=data, dest_file_name=file_name)
print(f"'{file_name}' created successfully.")
# Read data from the ODS file
sheet = pyexcel.get_sheet(file_name=file_name)
print("\nRead data from ODS file:")
for row in sheet:
print(row)
# You can also get a dictionary or other formats
book_dict = pyexcel.get_book_dict(file_name=file_name)
print("\nBook dictionary:", book_dict)
finally:
# Clean up the created file
if os.path.exists(file_name):
os.remove(file_name)
print(f"Cleaned up '{file_name}'.")