405-python-docx

python-docx is a Python library for reading, creating, and updating Microsoft Word 2007+ (.docx) files.

https://pypi.org/project/python-docx/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from docx import Document

document = Document()

document.add_paragraph("It was a dark and stormy night.")

# docx.text.paragraph.Paragraph object at 0x10f19e760>

document.save("dark-and-stormy.docx")

document = Document("dark-and-stormy.docx")

document.paragraphs[0].text

# 'It was a dark and stormy night.'