0

I have a functioning script to generate multiple word documents based on an input of variables and a template. What I want to do is create one single word document with all of the templates appended.

Here is my current code:

from docxtpl import DocxTemplate
import pandas as pd

doc = DocxTemplate("template.docx")

df = pd.read_csv("input.csv")

for index, row in df.iterrows():
        context = {'field1': row['field1'],
                   'field2': row['field2'],
                   'field3': row['field3'],
                   'field4': row['field4']}
        doc.render(context)
        doc.save(f"generated_doc_{index}.docx")
  • What do you mean by creating one document with templates appended? Can you provide more details or sample images on what you're trying to create? – benkyou Aug 30 '23 at 07:57

0 Answers0