0% found this document useful (0 votes)
5 views2 pages

Python Docx Module

Word documents are structured with three object levels: run objects, paragraph objects, and document objects, making them incompatible with standard text editors. The python-docx module allows for manipulation of these documents in Python, including the creation of ordered and unordered lists using the .add_paragraph() method. Users can customize lists with different styles for indentation and formatting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Python Docx Module

Word documents are structured with three object levels: run objects, paragraph objects, and document objects, making them incompatible with standard text editors. The python-docx module allows for manipulation of these documents in Python, including the creation of ordered and unordered lists using the .add_paragraph() method. Users can customize lists with different styles for indentation and formatting.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Word documents contain formatted text wrapped within three object levels.

The
Lowest level- run objects, middle level- paragraph objects, and highest level-
document object. So, we cannot work with these documents using normal text
editors. But, we can manipulate these word documents in python using the python-
docx module. Pip command to install this module is:
pip install python-docx
Python docx module allows users to manipulate docs by either manipulating the
existing one or creating a new empty document and manipulating it. It is a
powerful tool as it helps you to manipulate the document to a very large extent.
There are two types of lists:
 Ordered List
 Unordered List
To add an ordered/unordered list in a Word document there are styles available in
the .add_paragraph() method of the document object.
Syntax: doc.add_paragraph(String s, style=None)
Parameters:
 String s: It is the string data that is to be added as a paragraph. This string
can contain newline character '\n', tabs '\t' or a carriage return character '\r'.
 Style: It is used to set style.
Ordered List
Styles to add an ordered list are:
Sr.
Style Name Description
No.
1. List Number It adds an ordered list in the word document.
List Number It adds an ordered list with a single tab indentation in the
2.
2 word document.
List Number It adds an ordered list with double tab indentation in the word
3.
3 document.
Note: Each list-point is considered as a paragraph in a list so you have to add each
point as a new paragraph with the same style name.

You might also like