File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
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' )
Original file line number Diff line number Diff line change
1
+ You can read tutorial https://www.roytuts.com/create-header-and-footer-in-word-document-using-python/
You can’t perform that action at this time.
0 commit comments