Hi Jon,
Thank you for your update.
This is not possible to create document for each project to get an unknown list of corrections using mail merge. However, this would be possible by using the below workaround, Generate each project separately and merge into one document using cloning and merging concept.
Please refer the below code snippet for your reference:
OleDbCommand cmd2 = new OleDbCommand("select * from MainTable", conn);
//Excute Query
IDataReader dataReader2 = cmd2.ExecuteReader();
while (dataReader2.Read())
{
// Create a new document
doc = new WordDocument();
// Load the template.
doc.Open((System.IO.Path.Combine(dataPath, @"project.doc")), FormatType.Doc);
//Select from Maintable
sql1 = "select * from MainTable where Project=" + "'" + dataReader2.GetValue(1).ToString() + "'";
cmd = new OleDbCommand(sql1, conn);
//Excute Query
IDataReader dataReader1 = cmd.ExecuteReader();
//Select from subtable
sql = "select Correction from SubTable where SubTable.Project=" + "'" + dataReader2.GetValue(1).ToString() + "'";
cmd1 = new OleDbCommand(sql, conn);
DataTable table = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
da.Fill(table);
table.TableName = "SubTable";
// Execute Mail Merge with groups.
doc.MailMerge.ExecuteGroup(table);
// Execute Mail Merge
doc.MailMerge.Execute(dataReader1);
doc.Save("Sample.doc");
// Enumerate all the sections from the template document.
foreach (IWSection sec in doc.Sections)
{
// Cloning all the sections one by one and merging it to the new document.
doc1.Sections.Add(sec.Clone(doc1));
// Setting section break code to be the same as the template.
doc1.LastSection.BreakCode = sec.BreakCode;
}
You can download the sample from the below link:
http://websamples.syncfusion.com/samples/DocIO.Windows/F61754/main.htmHerewith I have attached the generated document for your reference:
sample1.docPlease let me know if you have any other queries.
Best Regards,
Bhuvaneswari