Skip to main content

Performs a Mail Merge on docx (Microsoft Office Word) files

Project description

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

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

docx-mailmerge-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file docx-mailmerge-0.1.0.tar.gz.

File metadata

File hashes

Hashes for docx-mailmerge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a1d33f645d8667136cde5d523ab3b3a353b1909d560528d33c5c09754a2808d3
MD5 72eb5170fd9114bdd67baf92afb92e3c
BLAKE2b-256 c9b48b3e1ff7f13028eda5c7971ef0c0993a8240d248d296f13398d58e529a2f

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