Skip to main content

docx Mail Merge

Build Status

Performs a Mail Merge on Office Open XML (docx) files. Can be used on any system without having to install Microsoft Office Word.

Installation

Installation with pip:

$ pip install docx-mailmerge

Usage

Open the file.

from mailmerge import MailMerge
document = MailMerge('input.docx')

List all merge fields.

print document.get_merge_fields()

Merge fields, supplied as kwargs.

document.merge(field1='docx Mail Merge',
               field2='Can be used for merging docx documents')

Merge table rows. In your template, add a MergeField to the row you would like to designate as template. Supply the name of this MergeField as anchor parameter. The second parameter contains the rows with key-value pairs for the MergeField replacements.

document.merge_rows('col1',
                    [{'col1': 'Row 1, Column 1', 'col2': 'Row 1 Column 1'},
                     {'col1': 'Row 2, Column 1', 'col2': 'Row 2 Column 1'},
                     {'col1': 'Row 3, Column 1', 'col2': 'Row 3 Column 1'}]

Write document to file. This should be a new file, as ZipFile cannot modify existing zip files.

document.write('output.docx')

Todo / Wish List

  • Preserve formatting of the merge field, currently it defaults to the formatting of the containing text.

  • Image merging.

Contributing

  • Fork the repository on GitHub and start hacking

  • Send a pull request with your changes

Metadata

Release files for docx-mailmerge 0.1.1

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

Source distribution (sdist)

Source distribution for docx-mailmerge 0.1.1
File Size Uploaded
docx-mailmerge-0.1.1.tar.gz 4.2 kB Details

Release files / docx-mailmerge-0.1.1.tar.gz

Download URL docx-mailmerge-0.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9185beda443bd208abb63bad5ae9d0ca4da4d74df9f585f8c5006c3fa9e4fc74
BLAKE2b-256 checksum
How to use checksums
2bd20df1d36f8a7294e8e2cb1907545b6bb83dda09498fcf8b9629a9284e88b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

This release

0.1.1 This release

1 release file

0.1.0

1 release file

0.0.2

1 release file

0.0.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