ezodf
ezodf is a Python package for creating new or opening existing OpenDocument (ODF) files, such as text documents (.odt) and spreadsheets (.ods), to extract, add, modify, or delete document data. The project's current version is 0.3.2, released in December 2015, and is classified as 'Alpha' development status, indicating potential API instability. While the main PyPI package sees limited activity, forks like 'pyexcel-ezodf' provide ongoing maintenance.
Warnings
- gotcha ezodf does NOT include a calculation engine for spreadsheets. Formulas are stored as strings only. Changes like inserting/deleting rows/columns will NOT update cell references in formulas and can break them, requiring manual recalculation or external tools.
- gotcha When opening spreadsheet documents, `ezodf` uses 'expand strategies' to prevent memory overflows. The default strategy ('all_less_maxcount') may not accurately represent the original sheet layout and can potentially break cell references, especially with many repeated rows/columns. The 'all' strategy guarantees layout but can lead to memory issues for large files.
- deprecated The primary `ezodf` package on PyPI (0.3.2) has not seen updates since December 2015 and is marked as 'Alpha' development status. Active maintenance appears to have shifted to forks like `pyexcel-ezodf` or related projects.
- gotcha There are reported `SyntaxWarning: invalid escape sequence` issues with Python 3.13, indicating potential compatibility problems with very recent Python versions due to the library's age.
Install
-
pip install ezodf
Imports
- newdoc
from ezodf import newdoc
- opendoc
from ezodf import opendoc
- Paragraph
from ezodf import Paragraph
- Heading
from ezodf import Heading
- Sheet
from ezodf import Sheet
Quickstart
from ezodf import newdoc, Paragraph, Heading, Sheet
import os
# Create a new text document (.odt)
odt_doc = newdoc(doctype='odt', filename='text_document.odt')
odt_doc.body += Heading("Chapter 1 - Introduction")
odt_doc.body += Paragraph("This is the first paragraph of the document.")
odt_doc.body += Paragraph("Here is some more text.")
odt_doc.save()
print(f"Text document saved to {os.path.abspath('text_document.odt')}")
# Create a new spreadsheet document (.ods)
ods_doc = newdoc(doctype='ods', filename='spreadsheet_document.ods')
sheet = Sheet('MySheet', size=(5, 5)) # Create a sheet named 'MySheet' with 5x5 cells
ods_doc.sheets += sheet
sheet['A1'].set_value("Product Name")
sheet['B1'].set_value("Quantity")
sheet['C1'].set_value("Price")
sheet['A2'].set_value("Laptop")
sheet['B2'].set_value(2)
sheet['C2'].set_value(1200, currency='USD')
sheet['D4'].formula = "of:=SUM([.B2];[.C2])" # Example formula, ezodf has no calculation engine
ods_doc.save()
print(f"Spreadsheet document saved to {os.path.abspath('spreadsheet_document.ods')}")
# To open and modify an existing document (example)
# from ezodf import opendoc
# existing_doc = opendoc('text_document.odt')
# existing_doc.body.append(Paragraph('Added a new paragraph after opening.'))
# existing_doc.saveas('updated_text_document.odt')