-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateWord.py
44 lines (36 loc) · 932 Bytes
/
createWord.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
36
37
38
39
40
41
42
43
44
import docx
from docx.shared import RGBColor, Pt
import glob
import re
import sys
def get_ans(file):
f = open(file, "r")
ans = f.read()
regex = re.compile('[^A-Z]')
ans = regex.sub('', ans)
print(ans)
# ans = [ord(char) - 64 for char in list(ans)]
ans = list(ans)
print(ans)
return ans
def create_word(ans = False):
doc = docx.Document()
for index in range(len(images)):
p = doc.add_paragraph()
r = p.add_run()
r.add_picture(images[index])
if(ans):
r.add_text(ans[index])
r.font.color.rgb = RGBColor(255, 0, 0)
r.font.size = Pt(18)
return doc
if __name__ == '__main__':
images = glob.glob("img/*.png")
print(images)
if len(sys.argv) == 2:
ans = get_ans(sys.argv[1])
doc = create_word(ans)
else:
doc = create_word()
doc.save('Output.docx')
print("\nFinish !!!")