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.
What is Python-DOCX?
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.
At A Glance
An overview of Python-DOCX features.
- Create DOCX
- Modify DOCX
- Add Paragraphs
- Add table
- Insert image
- Text formatting
- Add heading
- Page break
- Set colors
- Text alignment
- Bookmarks support
Python-DOCX only requires Python 2.6 & above
- Python 2.6, 2.7, 3.3, or 3.4
- lxml >= 2.3.2
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.
Python API to Create Word DOCX Documents
Python-DOCX library provides functionality for the 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, insert tables, font styles support, text formatting, and more. Using the following steps you can easily create a Microsoft Word document in your Python app easily.
Creatre Word Easily
- Initialize object of FastExcel
- Create workbook
- Populate row data
- Write Excel
Create Word Fastly - Python
// initialize document object document = Document() // add heading document.add_heading('Document Title', 0) // add paragraph p = document.add_paragraph('A plain paragraph having some ') // style paragraph p.add_run('bold').bold = True p.add_run(' and some ') p.add_run('italic.').italic = True // save word document document.save('demo.docx')
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 rows or columns, 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.