Skip to main content

This is a minimal module for creating ODT files based on ODT templates and dictionaries of values.

Note that the template rendering is based on regular expression matches on the ODT internal XML data; as such it should not be considered robust and will most certainly fail on some inputs. However, it’s “good enough” to be very useful considering the tiny code footprint - there are more lines of documentation than code here!

Just be sure to test your templates…

Example::

from odt_template import render_odt_template

# Assuming a template that has:
#   - A @TO@ marker somewhere on the page
#   - A table with a row containing @CHILD@ and @NAUGHTY@ markers
#   - An embedded image named XMAS.png
#
render_odt_template('xmas-template.odt', 'simpsons-family.odt', {
    'to': 'Santa Claus',
    'child': [
        {'child': 'Bart', 'naughty': 'yes'},
        {'child': 'Lisa', 'naughty': 'no'},
        {'child': 'Maggie', 'naughty': 'no'}
    ],
    'Pictures/XMAS.png': open('pretty-tree.png', 'r').read()
})

Why doesn’t my template work?

LibreOffice has probably injected random formatting markup in the middle of your placeholders, preventing the tool from recognizing them. Using “Format, Clear Direct Formatting” and then reformatting again (taking care to always select entire placeholders) usually helps.

Contributions and bug reports

Please file pull requests or open issues on this project’s Github repository: https://github.com/BjarniRunar/odt-templater/

Release files for odt_templater 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for odt_templater 0.1.2
File Size Uploaded
odt_templater-0.1.2.tar.gz 3.9 kB Details

Release files / odt_templater-0.1.2.tar.gz

Download URL odt_templater-0.1.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c161e13b2c8ecbceb44cad0c5eba9a28819cc7ddcf1773df36b729b2f95975d6
BLAKE2b-256 checksum
How to use checksums
632a0ded7a5e9cedf7e078cca6dbf630a2008aa31a45c031f411a08dc526948b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page