Spaces:
Running
Running
File size: 607 Bytes
eb097b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# word_updater.py
from docx import Document
from docx.shared import RGBColor
def is_red(run):
color = run.font.color
return color and color.rgb == RGBColor(255, 0, 0)
def fill_template_with_data(template_path, output_path, data):
doc = Document(template_path)
for para in doc.paragraphs:
for run in para.runs:
if is_red(run):
for key in data:
if key.lower() in run.text.lower():
run.text = run.text.replace(run.text, data[key])
break
doc.save(output_path)
return output_path |