MailMerge Attribute for properties

Is there a way to provide an object with properties with an attribute containing information about the MergeField in Word? The property name is different from the name of the MergeField in Word. If possible with format?


For example:

public class Invoice {

// Set or Get the Invoice Number
[MailMerge("Belegnummer")]
public string InvoiceNo { get; set; }

// Set or Get the Total price of the invoice
[MailMerge("Gesamtpreis", "C2")]
public decimal TotalPrice { get; set; }

// Get all invoice items 
public List<InvoiceItem> Items { get; }

// Set or Get the invoice recipient
public InvoiceRecipient Recipient { get; set; }

// ...

}

public class InvoiceItem {

// Set or Get the name of the item
[MailMerge("ArtikelBezeichnung")]
public string ItemName { get; set; }

// Set or Get the net price
[MailMerge("EinzelpreisNetto", "C2")]
public decimal NetPrice { get; set; }

// Set or Get the Quantitiy
[MailMerge("Menge", "N3"]
public decimal Qty { get; set; }

// Get the totel net price of the item
[MailMerge("GesamtpreisNetto", "C2"]
public decimal TotalNetPrice => this.GetTotalNetPrice();

// ...

private decimal GetTotalNetPrice() {

return this.Qty * this.NetPrice;

}

}


public class  InvoiceRecipient {

// Set or Get the name
[MailMerge("EmpfaengerName")]
public string Name { get; set; }


// Set or Get the street
[MailMerge("EmpfaengerStrasseHsnr")]
public string Street { get; set; }


// ....

}


1 Reply

KP Kathiresan Paranthaman Syncfusion Team August 4, 2025 05:52 PM UTC

Hi Danny,
Regarding: Performing Mail merge with objects in Syncfusion DocIO.
When performing a mail merge operation using DocIO, it is not possible to directly use an object in the mail merge as a parameter. However, it is possible to perform mail merge by converting object data into a DataTable using the MailMergeDataTable class.
This conversion allows us to use a list of objects as the data source. Below is an example where the object list is converted into a data table and used in the mail merge operation.

// Gets the organization details as an "IEnumerable" collection.
List<Organization> organizationList = GetOrganizations();
// Creates an instance of MailMergeDataTable by specifying the mail merge group name and collection.
MailMergeDataTable dataTable = new MailMergeDataTable("Organizations", organizationList);
// Creates employee details.
List<EmployeeDetails> employees = new List<EmployeeDetails>();
employees.Add(new EmployeeDetails("Thomas Hardy", "1001", "05/27/1996"));
List<Organization> organizations = new List<Organization>();
organizations.Add(new Organization("UK Office", "120 Hanover Sq.", "London", "WX1 6LT", "UK", employees)).

Regarding: Property names are different from the name of the MergeField.
While performing mail merge in DocIO, the property names in your object must exactly match the merge field names used in the Word template. This matching is necessary for the merge field to execute properly.

Kindly refer the below documentation:
https://help.syncfusion.com/document-processing/word/word-library/net/mail-merge/mail-merge-for-nested-groups

Regards,
Kathiresan.


Loader.
Up arrow icon