0% found this document useful (0 votes)
101 views

Python-Docx: What It Can Do

python-docx is a Python library for creating and updating Microsoft Word (.docx) files. It allows adding headings, paragraphs, pictures, tables, and other document elements. The documentation provides an overview of the library's capabilities, user guide, API reference, and information for contributors.

Uploaded by

Fanny lfjfslf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Python-Docx: What It Can Do

python-docx is a Python library for creating and updating Microsoft Word (.docx) files. It allows adding headings, paragraphs, pictures, tables, and other document elements. The documentation provides an overview of the library's capabilities, user guide, API reference, and information for contributors.

Uploaded by

Fanny lfjfslf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

python-docx — python-docx 0.8.10 documentation https://python-docx.readthedocs.

io/en/latest/

python-docx
Release v0.8.10 (Installation)

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

What it can do
Here’s an example of what python-docx can do:

from docx import Document


from docx.shared import Inches

document = Document()

document.add_heading('Document Title', 0)

p = document.add_paragraph('A plain paragraph having some ')


p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True

document.add_heading('Heading, level 1', level=1)


document.add_paragraph('Intense quote', style='Intense Quote')

document.add_paragraph(
'first item in unordered list', style='List Bullet'
)
document.add_paragraph(
'first item in ordered list', style='List Number'
)

document.add_picture('monty-truth.png', width=Inches(1.25))

records = (
(3, '101', 'Spam'),
(7, '422', 'Eggs'),
(4, '631', 'Spam, spam, eggs, and spam')
)

table = document.add_table(rows=1, cols=3)


hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Qty'
hdr_cells[1].text = 'Id'
hdr_cells[2].text = 'Desc'
for qty, id, desc in records:
row_cells = table.add_row().cells
row_cells[0].text = str(qty)  v: latest 
row_cells[1].text = id
row_cells[2].text = desc

1 of 4 24/9/20, 10:33 pm
python-docx — python-docx 0.8.10 documentation https://python-docx.readthedocs.io/en/latest/

document.add_page_break()

document.save('demo.docx')

User Guide
Installing
Quickstart
Working with Documents
Working with Text
Working with Sections
Working with Headers and Footers
API basics
Understanding Styles
Working with Styles
Understanding pictures and other shapes

API Documentation
Document objects
Document constructor
Document objects
CoreProperties objects
Document Settings objects
Style-related objects
Styles objects
BaseStyle objects
_CharacterStyle objects
_ParagraphStyle objects
_TableStyle objects
_NumberingStyle objects
LatentStyles objects
_LatentStyle objects
Text-related objects
Paragraph objects
ParagraphFormat objects
Run objects
 v: latest 
Font objects
TabStop objects

2 of 4 24/9/20, 10:33 pm
python-docx — python-docx 0.8.10 documentation https://python-docx.readthedocs.io/en/latest/

TabStops objects
Table objects
Table objects
_Cell objects
_Row objects
_Column objects
_Rows objects
_Columns objects
Section objects
Sections objects
Section objects
_Header and _Footer objects
Shape-related objects
InlineShapes objects
InlineShape objects
DrawingML objects
ColorFormat objects
Shared classes
Length objects
RGBColor objects
Enumerations
MSO_COLOR_TYPE
MSO_THEME_COLOR_INDEX
WD_PARAGRAPH_ALIGNMENT
WD_BUILTIN_STYLE
WD_CELL_VERTICAL_ALIGNMENT
WD_COLOR_INDEX
WD_LINE_SPACING
WD_ORIENTATION
WD_TABLE_ALIGNMENT
WD_ROW_HEIGHT_RULE
WD_SECTION_START
WD_STYLE_TYPE
WD_TAB_ALIGNMENT
WD_TAB_LEADER
WD_TABLE_DIRECTION
WD_UNDERLINE

 v: latest 
Contributor Guide

3 of 4 24/9/20, 10:33 pm
python-docx — python-docx 0.8.10 documentation https://python-docx.readthedocs.io/en/latest/

Analysis

 v: latest 

4 of 4 24/9/20, 10:33 pm

You might also like