Python API to Create & Edit Microsoft Word Documents

Open Source Python Library for Managing MS Word files, add Table & Images to Word DOCX files & more.

 

Python-DOCX is an Open Source Python library that gives software developers the capability to work with Microsoft Word (Docx) inside their own applications. The API can create and modify Word documents, which have the .docx file extension

The API is very productive and supports several important word processing features such as opening a document, adding a paragraph, adding a heading, adding a page break, adding a table, inserting images, applying a paragraph style, text formatting and much more.

Getting Started with Python-DOCX

Python-DOCX is hosted on PyPI, so It is very simple to install it.  It can be installed with pip using the following command.

Install Python-DOCX via pip command

 pip install python-docx  

It can also be installed via easy_install but is not recommended.

Install Python-DOCX Easy_install command

easy_install python-docx 

It can also be installed manually by downloading it from PyPI, unpack it and running setup.py:

Manual installation

tar xvzf python-docx-{version}.tar.gz
cd python-docx-{version}
python setup.py install

Python API to Create Word DOCX Documents

Python-DOCX library provides functionality for creation as well as manipulation of Microsoft word DOCX documents. The API also enables software developers to modify word documents. Now, to open a word document, create an instance along with passing the path to the document. You also can add images, add headings, inset table, font styles support, text formatting and more.

Add a Table to Word DOCX Document

Python-DOCX API allows developers to add tables to a Word DOCX Document inside Python applications. There are several properties and methods linked to a table. In order to use the table, you will need to use them, for example accessing a table cell, table-border, accessing individual row or column and more.

Add Images to Word DOCX Files

Python-DOCX provides Software programmers the ability to insert images inside their Word DOCX document. To add an image you need to provide the name and location of the image. By default, the added image appears at the native size. You can specify both the width and height of the image. The Inches and Cm classes are provided to let you specify measurements in convenient units.