-
Valentin Groues authoredValentin Groues authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
docx_helper.py 606 B
from docx import Document
def process_file(path_to_docx, path_to_new_docx, changes_to_apply):
"""
Tries to open the docx document using given path to file.
Then, applies the transformations- replaces template tags
in format of ##name## to values specified in the second
argument.
"""
doc = Document(path_to_docx)
for paragraph in doc.paragraphs:
for placeholder, replacement in changes_to_apply.items():
if placeholder in paragraph.text:
paragraph.text = paragraph.text.replace(placeholder, replacement)
doc.save(path_to_new_docx)