Free Support Forum -

Mailmerge with IList object collection


Are you planning to add support to start a mailmerge on an IList collection containing other objects?


= collection of contacts containing an object Contact

Contact object with properties like:

  • Lastname
  • Firstname
  • Address.Street
  • Address.Country.Name
  • Friends[0].Name

    Currently you have to convert this a dataset and then you can use the mailmerge. It’s easier if you can bind it directly.

    ps. please note the nested (collection) properties :wink:



Thanks for the idea.

Mail merge in Aspose.Word needs to be able to retrieve a value by a field name. I don't quite see how to represent name-value pairs using IList in a manner that is generic enough to be useful for many customers. I might allow mail merge to accept IDictionary, but I don't think this is what you are after.

The IList or IEnumerator contains the objects that are used for
the mailmerge For each object in the IList/IEnumerator you execute code
like this (= the same as a DataSet with multiple records):

What you basically do is:

MSWord contains: MergeField “Contact.LastName”, MergeField “Contact.Address.Country.Name”

long id = 100;

Contact contact = GetContactFromWhatEver(id)


The overloaded mailmerge method just executes on all the fields in the word document.:

result = Eval(contact, mergeFieldFromWord, [formatting])

You have to implement contact.Address.Country.Name yourself in a loop:

object newValue = Eval(contact, “Address”);

newValue = Eval(newValue, “Country”);

result = Eval(newValue, “Name”);

the same is true for contact.Friends[0].Name… Parse it first and
recusirvely execute it with Eval…(i think you need reflection for
this, but i’m not sure)