Regarding execute with region

Hi,
can i use doc.MailMerge.ExecuteWithRegions(datatable) inside a loop
where datatable contains different records on each run
can u suggest a better approach to make the above method as dynamic
with regards
Durai

Hi
Thanks for your inquiry. I think that you can clone original template in each iteration of the loop. For example here is code example:

// Open template document
Document doc = new Document(@"Test020\in.doc");
// Start loop
for (int i = 0; i < 10; i++)
{
    // Clone original document
    Document docClone = (Document)doc.Clone(true);
    // Execute mail merge
    // You should get corresponding data from your DB.
    // In the example I use the same datasource for each document
    docClone.MailMerge.ExecuteWithRegions(table);
    // Save document
    docClone.Save(String.Format(@"Test020\out_{0}.doc", i));
}

If you need to merge documents together then you can use the following code:

// Open template document
Document doc = new Document(@"Test020\in.doc");
// Open or create master document
Document master = new Document();
// Start loop
for (int i = 0; i < 10; i++)
{
    // Clone original document
    Document docClone = (Document)doc.Clone(true);
    // Execute mail merge
    // You should get corresponding data from your DB.
    // In the example I use the same datasource for each document
    docClone.MailMerge.ExecuteWithRegions(table);
    // Set first section break of sub document
    docClone.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
    // Merge master document and sub document
    AppendDoc(master, docClone);
}
// Save output document
master.Save(@"Test020\out.doc");

Also see th efollowing link to learn how to append one documen tto another
https://docs.aspose.com/words/net/insert-and-append-documents/
I hope this could help you.
Best regards.