Skip to content
Use the Jinja Template System to perform openoffice mailmerges on the commandline
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



This is an early proof of concept. Currently this is VERY hardcoded, but I thought it would be worth releasing: The file requires a file called 'data.csv'

If you're comfortable with python and the commandline you should be able to find your way around.


The script expects a 'data.csv' file and 'content4.xml.tmpl' file in the same directory

You will need to install Jinja:

easy_install Jinja2

About the content4.xml.tmpl file

This file is typically created as follows:

  1. Create an OpenOffice Document and include Jinja style syntax for merge fields
  2. Unpack the document using an unzip program
  3. Name the content.xml file content4.xml.tmpl
  4. Get a suitable data.csv file with fields that match the content4.xml.tmpl
  5. run the command to execute the merge
  6. put the merged output (content.xml file) back into a copy of the unpacked openoffice document
  7. zip it up again (rename to odt if necessary)


While in the directory with the 'data.csv' and 'content4.xml.tmpl' run the following:

python > content.xml

The result will be an ODT (openoffice style) content.xml file

This can be added to an unzipped openoffice document (ODT) to replace the content.xml, then rezip and rename to ODT. The resulting document will contain your merged output.


In additon to, there is also which takes a content.xml file and outputs an easier to read version. Pretty print is most oftent used on files generated by OpenOffice since they tend to save on white space at the expense of readability. Still very badly coded, it takes no input and expects to be in the same directory as the content.xml file.


python > cleanedupversion.xml

Typical Project

Create a file and include fields like:

{{user['First_Name']}} {{user['Last_Name']}}

These would be derived from the data.csv and then merged into the template.

Create directory for the project:

mkdir myproject
mv myodtfile.odt myproject

mkdir myproject/source
cd myproject/source
unzip ../myodtfile.odt

The result will be a source directory containing the openoffice file structure, including a content.xml file

Run prettyprint on the content.xml:

path/to/ content.xml > prettycontent.xml
cp prettycontent.xml content.xml

Then edit the content.xml to make any customizations.

Finally follow the instructions at the top to create a new merge of the odt.

You can’t perform that action at this time.