1. Products
  2.   Word Processing
  3.   Python
  4.   Python-DOCX
 
  

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.

Previous Next

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.

Create Word Easily

  1. Initialize object of FastExcel
  2. Create workbook
  3. Populate row data
  4. 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.

 English