In Below code sometimes i get addressline 2 and addressline 3 as null, in that case i need to remove that empty space, now am getting space with ,
case "SupplierAddress":
doc.MailMerge.Execute(["SupplierAddress"],
[DocumentDetailsList.SupplierParty!.AddressLine1 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.AddressLine2 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.AddressLine3 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.PostalCode + " " + DocumentDetailsList.SupplierParty!.CityName + "," + Environment.NewLine +
GetStateName(Convert.ToInt32(DocumentDetailsList.SupplierParty!.StateCode)) + "," + Environment.NewLine +
GetCountry.GetCountryNameUsingShortName(DocumentDetailsList.SupplierParty!.Country!)]);
break;
@ParvezShaik You can use CleanupOptions.
For example:
doc.MailMerge.CleanupOptions = Aspose.Words.MailMerging.MailMergeCleanupOptions.RemoveEmptyParagraphs;
but , will stay if i use cleanupOptions, Is there any condition to check within
doc.MailMerge.Execute() method
for below scenario if i get example woyld be appreciated
doc.MailMerge.Execute(["SupplierAddress"],
[DocumentDetailsList.SupplierParty!.AddressLine1 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.AddressLine2 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.AddressLine3 + "," + Environment.NewLine +
DocumentDetailsList.SupplierParty!.PostalCode + " " + DocumentDetailsList.SupplierParty!.CityName]);
@ParvezShaik You can use FieldMergingCallback to edit field result and replace some empty spaces. Here is an example:
doc.MailMerge.FieldMergingCallback = new FieldValueMergingCallback();
/// <summary>
/// Edits the values that MERGEFIELDs receive during a mail merge.
/// The name of a MERGEFIELD must have a prefix for this callback to take effect on its value.
/// </summary>
private class FieldValueMergingCallback : IFieldMergingCallback
{
/// <summary>
/// Called when a mail merge merges data into a MERGEFIELD.
/// </summary>
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
e.FieldValue = e.FieldValue.ToString().Replace($",{Environment.NewLine},", "");
}
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
// Do nothing.
}
}