Code Monkey home page Code Monkey logo

docx-mailmerge's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.