-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateWord.py
35 lines (24 loc) · 1.05 KB
/
updateWord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from docx import Document
def replace_text(doc, old_text, new_text):
for paragraph in doc.paragraphs:
if old_text in paragraph.text:
for run in paragraph.runs:
if old_text in run.text:
run.text = run.text.replace(old_text, new_text)
def addInfo(list, template):
for student in list:
doc = Document(template)
replace_text(doc, "Name", student.name)
replace_text(doc, "CLASS", student.sem + student.dept)
replace_text(doc, "EVENT", student.event1)
# Save the modified document
doc.save(f"Final_Word//{student.name}_certificate.docx")
if student.event2 != "":
doc = Document(template)
replace_text(doc, "Name", student.name)
replace_text(doc, "CLASS", student.sem + student.dept)
replace_text(doc, "100MSPRINTANDJUMP", student.event2)
doc.save(f"Final_Word//{student.name}_certificate2.docx")
# doc=Document("template.docx")
# for paragraph in doc.paragraphs:
# print(paragraph.text)