Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c74834

Browse files
authored
Add files via upload
1 parent dab397e commit 0c74834

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from docx import Document
2+
3+
document = Document()
4+
5+
#header section
6+
header_section = document.sections[0]
7+
header = header_section.header
8+
9+
#footer section
10+
footer_section = document.sections[0]
11+
footer = footer_section.footer
12+
13+
#header text
14+
header_text = header.paragraphs[0]
15+
header_text.text = "Header of my document"
16+
17+
#heading of the document
18+
document.add_heading('Document Title', 0)
19+
20+
21+
#paragraph
22+
p = document.add_paragraph('A plain paragraph')
23+
24+
#footer text
25+
footer_text = footer.paragraphs[0]
26+
footer_text.text = "Footer of my document"
27+
28+
#write to docx
29+
document.save('simple.docx')

python-docx-header-footer/readme.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
You can read tutorial https://www.roytuts.com/create-header-and-footer-in-word-document-using-python/

python-docx-header-footer/simple.docx

36.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)