oodocx is a fork/modification/Python 3 port of Mike MacCana's excellent python-docx module. Here are some of the differences of oodocx from python-docx:
1. Object Oriented. As the name suggests, oodocx has an object-oriented aspect. The Docx class represents the various files that comprise a docx file, which is simply a zip file that contains primarily xml files. The document.xml file is the main document that holds most of the content that you find in a word document. However, this module also gives you easy access to most of the other files that typically comprise a docx file as attributes of the Docx class. For example, the root element in styles.xml of a Docx object named "d" can be accessed as d.styles. This allows for greater control of the look, feel, and metadata of a docx file.
2. Python 3 compatible.
3. Expanded functionality, particularly for people with limited knowledge of xml who want to get started quickly on their docx scripting projects. Some examples include the modify_font and modify_paragraph functions, which allow for easy modification of common font and paragraph properties of an element or a list of elements.
First, ensure that you have the appropriate version of lxml installed. Then, clone this repository, navigate your shell window to the oodocx directory folder that contains the setup.py file, and enter "python setup.py install" (or just "setup.py install", depending on how you execute python files on your computer) First of all, be sure to check out the /examples folder for basic examples of this moduled = oodocx.Docx()
body = d.get_body()
body.append(oodocx.paragraph('Hello world!'))
d.save('hello.docx')
Open a document, insert a paragraph after the paragraph containing the word "apple", and save it somewhere else
d = oodocx.Docx(r'C:\users\applecart\apples.docx')
body = d.get_body
apple_para = d.search('apple', result_type='paragraph')
pos = body.index(apple_para) + 1 #lxml
body.insert(pos, oodocx.paragraph('Bananas!')) #lxml
d.save(r'C:\users\bananstand\there's always money here.docx')
Note that the index() and insert() methods in the fourth and fifth lines of the above code are from the underlying lxml module. Check out the documentation here.