ezodf

0.3.2 · maintenance · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to create both a new OpenDocument Text (.odt) file with a heading and paragraphs, and a new OpenDocument Spreadsheet (.ods) file with a sheet, cell values, and a basic formula. It then saves both documents.

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')

view raw JSON →