'Can't insert single cell text into word template [Python, Xlwings, Docxtpl}

I'm trying to create a tool to automate some documents, I made a spreatsheet in excel that concatenates all the parts of the text allowing me to change variables such as name of recipent or serial numbers.

What I want to do now is to create a button that generates the document using a template and the text stored in a single cell. I managed to make a python script that can pull the data from both the excel file and the document but I must have made a mistake because while the delivery document is created when I run the script it doesn't have the text stored in my excel cell. Here is my code:

enos.chdir(sys.path[0])

def main():
wb = xw.Book.caller()
panel = wb.sheets['Adeudos']
doc = DocxTemplate('Formato.docx')

context = panel.range('Q2:R2').options(dict,numbers=lambda x: str(int(x))).value

output_name = f'Oficio.docx'


doc.render(context)
doc.save(output_name)
       


if __name__ == "__main__":
xw.Book("word_automation.xlsm").set_mock_caller()
main()

If you could also help me out with a way to insert the text of another cell into the name of the generated document that would be great.

Thanks for the help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source