Hi All
Hi David,
Document doc = new Document(MyDir + @“Doc2.docx”);<o:p></o:p>
string excelDS = @"c:\Temp\Book2.xlsx";
MailMergeSettings mms = doc.MailMergeSettings;
mms.DataSource = excelDS;
mms.MainDocumentType = MailMergeMainDocumentType.FormLetters;
mms.DataType = MailMergeDataType.Native;
mms.LinkToQuery = true;
mms.ViewMergedData = true;
mms.Query = "SELECT * FROM 'Sheet1$'";
doc.Save(MyDir + @"Out v16.11.0.docx");
Hi Tahir
Hi David,
david_foley_azyra_com:
The final Doc2_Out.docx has not mailmerged the data. When I try to open it I get the attached message, Message.jpg.
Hi Tahir
david_foley_azyra_com:
At the moment Doc2_out.docx seems to be the Mailmerge document. When I open in word is still has a connection to the Mailmerge Data source and I have to click Mailings / Finish & Merge to view the merged data.
Document doc = new Document(MyDir + "input.docx");
// Field values from the table are inserted into the mail merge fields found in the document.
// Export data to DataTable Using Aspose.Cells
doc.MailMerge.Execute(datatable);
doc.Save(MyDir + "MailMerge.ExecuteDataTable Out.docx");
private class HandleDateField : IFieldMergingCallback
{
///
/// This is called when merge field is actually merged with data in the document.
///
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
if (e.DocumentFieldName.Equals("datefieldname"))
{
// Insert the date using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(e.DocumentFieldName);
builder.Write(Convert.ToDateTime(e.FieldValue).ToString("MMMM dd, yyyy"));
// We have already inserted the field's value
e.Text = "";
}
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
// Do nothing.
}
}
Document doc = new Document(MyDir + "in.docx");
// Add a handler for the MergeField event.
doc.MailMerge.FieldMergingCallback = new HandleDateField();
doc.MailMerge.Execute(datatable);