Skip to main content

CLI harness for LibreOffice - Create and manipulate ODF documents, export to PDF/DOCX/XLSX/PPTX via LibreOffice headless

Project description

LibreOffice CLI

A stateful command-line interface for document editing, producing real ODF files (ZIP archives with XML). Designed for AI agents and power users who need to create and manipulate Writer, Calc, and Impress documents without a GUI or LibreOffice installation.

Prerequisites

  • Python 3.10+
  • click (CLI framework)

No other dependencies required -- uses Python stdlib (zipfile, xml.etree.ElementTree, json) for ODF generation.

Install Dependencies

pip install click

How to Run

All commands are run from the agent-harness/ directory.

One-shot commands

# Show help
python3 -m cli.libreoffice_cli --help

# Create a new Writer document
python3 -m cli.libreoffice_cli document new --type writer --name "Report" -o report.json

# Create with a page profile
python3 -m cli.libreoffice_cli document new --profile a4_portrait -o project.json

# Open a project and show info
python3 -m cli.libreoffice_cli --project project.json document info

# JSON output (for agent consumption)
python3 -m cli.libreoffice_cli --json --project project.json document info

Interactive REPL

python3 -m cli.libreoffice_cli repl
python3 -m cli.libreoffice_cli repl --project my_project.json

Inside the REPL, type help for all available commands.

Command Reference

Document

document new [--type writer|calc|impress] [--name N] [--profile P] [-o path]
document open <path>
document save [path]
document info
document profiles
document json

Available profiles: a4_portrait, a4_landscape, letter_portrait, letter_landscape, legal_portrait, presentation_16_9, presentation_4_3

Writer (Word Processor)

writer add-paragraph [--text T] [--position P] [--font-size S] [--bold] [--italic] [--alignment A]
writer add-heading [--text T] [--level 1-6] [--position P]
writer add-list [--items I ...] [--style bullet|number] [--position P]
writer add-table [--rows R] [--cols C] [--position P]
writer add-page-break [--position P]
writer remove <index>
writer list
writer set-text <index> <text>

Calc (Spreadsheet)

calc add-sheet [--name N] [--position P]
calc remove-sheet <index>
calc rename-sheet <index> <name>
calc set-cell <ref> <value> [--type string|float] [--sheet S] [--formula F]
calc get-cell <ref> [--sheet S]
calc list-sheets

Impress (Presentations)

impress add-slide [--title T] [--content C] [--position P]
impress remove-slide <index>
impress set-content <index> [--title T] [--content C]
impress list-slides
impress add-element <slide_index> [--type text_box] [--text T] [--x X] [--y Y]

Styles

style create <name> [--family paragraph|text] [--parent P] [--prop key=value ...]
style modify <name> [--prop key=value ...]
style list
style apply <style_name> <content_index>
style remove <name>

Style properties: font_size, font_name, bold, italic, underline, color, alignment, line_height, margin_top, margin_bottom

Export

export presets
export preset-info <name>
export render <output> [--preset odt|ods|odp|html|text] [--overwrite]

Session

session status
session undo
session redo
session history

JSON Mode

Add --json before the subcommand for machine-readable output:

python3 -m cli.libreoffice_cli --json --project p.json writer list

Running Tests

cd agent-harness
python3 -m pytest cli/tests/test_core.py -v        # Unit tests
python3 -m pytest cli/tests/test_full_e2e.py -v     # E2E tests (ODF validation)
python3 -m pytest cli/tests/ -v                      # All tests

Example Workflow

# Create a Writer document
python3 -m cli.libreoffice_cli document new --type writer --name "Quarterly Report" -o report.json

# Add content
python3 -m cli.libreoffice_cli --project report.json writer add-heading -t "Q1 Report" -l 1
python3 -m cli.libreoffice_cli --project report.json writer add-paragraph -t "Revenue grew by 15%."
python3 -m cli.libreoffice_cli --project report.json writer add-table --rows 3 --cols 2
python3 -m cli.libreoffice_cli --project report.json writer add-list -i "Product A" -i "Product B"

# Create and apply a style
python3 -m cli.libreoffice_cli --project report.json style create "Emphasis" --prop bold=true --prop color=#cc0000
python3 -m cli.libreoffice_cli --project report.json style apply "Emphasis" 1

# Save and export
python3 -m cli.libreoffice_cli --project report.json document save
python3 -m cli.libreoffice_cli --project report.json export render report.odt --preset odt --overwrite
python3 -m cli.libreoffice_cli --project report.json export render report.html --preset html --overwrite

ODF Format

Exported ODF files are valid ZIP archives containing:

  • mimetype (uncompressed, first entry) -- identifies the document type
  • content.xml -- document content in ODF XML
  • styles.xml -- document styles
  • meta.xml -- metadata (title, author, dates)
  • META-INF/manifest.xml -- manifest of all files

These files can be opened by LibreOffice, Apache OpenOffice, and other ODF-compatible applications.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cli_anything_libreoffice-1.0.0.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_anything_libreoffice-1.0.0-py3-none-any.whl (54.2 kB view details)

Uploaded Python 3

File details

Details for the file cli_anything_libreoffice-1.0.0.tar.gz.

File metadata

  • Download URL: cli_anything_libreoffice-1.0.0.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for cli_anything_libreoffice-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bf890b1541768fc94df73c737d8b6a6c6ed4e8d57a915ccda7f3202968a785cf
MD5 e79aca7171d0b014bddbee486ce43332
BLAKE2b-256 19d7920ce639f526b94eabd0779f4a78ead58e171489057509b8270e12a46678

See more details on using hashes here.

File details

Details for the file cli_anything_libreoffice-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cli_anything_libreoffice-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23fe82db543b4a5384dcf42fd6115a14ad2be68459f6af149a8e092153fb7716
MD5 84e9d0cc56a5cba57ff52348ed5f0ee8
BLAKE2b-256 20746d0fc56a97d416241774b89bc41da8d48c0ea7d3ae81a3e7c9e67895e312

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page