How to create and generate Word documents for Python Automation Office
This article mainly introduces the Python automation office Word document how to create and generate related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Python automation office Word document how to create and generate the article will have a harvest, let's take a look.
Save the generated word
Before we learn how to generate an word document, let's take a look at how to save the generated word file, because we'll need it soon.
How to use it:
Document_obj.save (file address)-> / home/demo.docx
The code example is as follows:
# coding:utf-8from docx import Documentdoc = Document () doc.save ('test.docx')
The running results are as follows:
Generate title
How to use it:
Title_obj = DocumentObj.add_heading (title content, title style level) returns the title object by calling the add_heading function through the Document object.
Title style level:
0