We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Multiple output Documents when using MailMerge.Execut(IMailMergeDataSource)

Is it possible to output multiple Documents using MailMerge.Execute(IdataSourceImplementation)? Consider a Document object ‘doc’ that is 1 page long with some merge fields in it.

//3 items in the datasource
exampleDataEntity ent1 = new exampleDataEntity(String "ent1");
exampleDataEntity ent2 = new exampleDataEntity(String "ent2");
exampleDataEntity ent3 = new exampleDataEntity(String "ent3");

//create the data source...
exampleDataEntityCollection myCollection = new exampleDataEntityCollection();

exampleDataSource myDataSource = new exampleDataSource(myCollection);//exampleDataSource implements  IMailMergeDataSource

doc.save(somePath);//Produces 1 document, 3 pages long.
  //each page is a copy of the original 1 page document with data from one of the exampleDataEntity replacing the mergeFields.
  //Is there a way to get 3 documents, each 1 page long?

Is there a way to get 3 documents, each 1 page long?


You can meet this requirement by implementing the following workflow:

DataTable dataTable = new DataTable("Payments");

dataTable.Columns.Add(new DataColumn("mf"));

DataRow dataRow;
for (int i = 1; i < 5; i++)
    dataRow = dataTable.NewRow();
    dataRow[0] = "field value_" + i;


Document doc = new Document("D:\\temp\\in.docx");

int x = 0;
foreach (Section sec in doc.Sections)
    Document temp = (Document)doc.Clone(false);
    temp.AppendChild(temp.ImportNode(sec, true));
    temp.Save("D:\\temp\\18.9_" + x + ".docx");