I'm working on a python script which analyses excel file and based on than filling in docx files with multiple variables using mailmerge library. For string values all is working fine but I have a problems with inserting image into a file. As I have to choose from 7 images for now as a workaround I just created 7 templates and I'm choosing the correct template based on some conditions but in the near future I will have more combination of images inside docx file and then creating like 50 templates is not a good option.
On google i found out that images can be inserted into docx file with below structure:
{ INCLUDEPICTURE "{ MERGEFIELD 1.png * MERGEFORMAT }" * MERGEFORMAT }
but I cannot make it work for me. Is it possible to insert path of a image into it and then Word would use it to insert an image? something like that:
{ INCLUDEPICTURE "{ path_to_image * MERGEFORMAT }" * MERGEFORMAT }
from mailmerge import MailMerge
document = MailMerge(template.docx)
document.merge(path_to_image="C:\\image.png")
document.write(document_name)
Thanks!