We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merge Field Sorting

Would like to be able to specify sorting on merge fields in order to sort data and leave it up to the owner of the word document to control what they would like to have sorted without any changes to code.

Does anyone have a viable solution for this?

Hi James,

Thanks for your inquiry. Aspose.Words does not provide any API to sort mail merge data. In your case, I suggest you please do the sorting in your data source (E.g DataTable or Array) before performing the mail merge.

Please let us know if you have any more queries.

Thanks for your reply. I’m a little confused because another Aspose staff member said it was possible. Here is the original thread where this was stated by aske012:

https://forum.aspose.com/t/67570

Hi James,

Thanks
for your inquiry. Unfortunately, at the moment Aspose.Words does not provide any API to sort data by mail merge field. However, you can pass sorted data source to mail merge engine to get the required output. E.g using DataView.Sort property, you can sort the DataTable and use it in mail merge.

MailMerge.ExecuteWithRegions Method (DataView) performs mail merge from a DataView into the document with mail merge regions.

MailMerge.Execute Method (DataView) performs mail merge from a DataView into the document.

These methods are useful if you retrieve data into a DataTable but then need to apply a filter or sort before the mail merge.

Hope this answers your query. Please let us know if you have any more queries.