How to implement filter/order by in MailMerge?

I need to implement filters and “order by” to order/filter rows (details) in any Table/repeating group in my application. I am using MailMerge.ExecuteWithRegions() with DataSet.
Here is what I have a the moment:
1)I am using IMailMergeDataSource and I have my own IMailMergeDataSource dataset.
2)I can add some data to <<TableStart >> mergefields in my templates - such as “order by” and “where” clauses. I could easily sort/filter data in memory if I have those.

The problem:
Obviously in general case I can have multiple <<TableStart >> fields FOR THE SAME TABLE.

It is obviolusly possible that order by/filters on those are different.

IMailMergeDataSource.GetChildDataSource(string tableName) does not giove
me currrent <<TableStart>> mergefield (only tablename) so I can’t extract my order by and/or
filter strings from this specific <<TableStart>>.

A stupid example for illustration only:
My data is Order<-Items for a Pizza shop.
I want to show all drinks in one grid and all non-drinks in a second grid.
So I have a template like:
<<TableStart Order>>
Oder no: <<orderNumber>>
<<TableStart Items filter=Items.IsDrink='Y>>
…Table of drinks here…
<<TableStart Items filter=Items.IsDrink='N>>

…Table of non-drinks here…


Note: if you were going to say “make drinks and non-drinks different tables in your dataset in your SQL/XML” — no can’t do that :-).
I have to be able to produce different merged documents from the same data, so that my end user can implement these 2 grids (drinks and non-drinks) by editing word template only - by applying filters "Item.IsDrink==‘Y’ or Item.IsDrink=‘N’ - i.e. without rewriting SQL to get data.

And of course sometimes you may want the same data appear in 2 grids but sorted differently (it does not matter for me if it is in the same template or different templates).
Again I can’t modify SQL so have to specify sort in the template…

Thanks for great support here!


Thank you for your interest in Aspose.Words. In one of future versions of Aspose.Words we are planning to add more reporting syntax. So you will be available filter sort or group data in region. I linked your request to the appropriate issue. You will be notified as soon as this feature is available.

Best regards,

Thanks this probably be sometime in 2013 I guess from “in one of future releases” - i.e. it is not in the plans yet…

Anyone has any ideas how I can implement it now?
All I need to do is to figure out which particular
merge field I am on when Aspose calls IMailMergeDataSource.GetChildDataSource really.
I guess I also need a way of figuring out when child merge finished and Aspose returns to merging parent

I am thinking of building a tree of TableStart/TableEnd pairs by going through the document before merge started and somehow following Merge progress through the tree (from my IMailMergeDataSource class).
Not very elegant.

Would this work? Any better ideas?

IMHO You might also consider adding a new IMailMergeDataSource2 interface
where GetChildDatasource signature is changed to something more generic like:

public IMailMergeDataSource GetChildDataSource(string tableName, Aspose.Fields.Field tableStartField)

Then custom datasource can implement one of the 2 interfaces may be?

I mean if you providing ways of extending MailMerge functionality then giving the programmers more info seems to be a good way to make sure programmers can actually use the feature.

Just my 2 cents.

Thank you for additional information and suggestions. I think, in your case, you can put information about sorting and filtering into the region name. Then you will be able to parse name of the region in your IMailMergeDatasource.
Best regards,

1)Oh you mean that I can make my Table name to have filter after a delimiter in it:
something like:
<<TableStart MyTable_%Filter_Price&gt_5.0>>
I see - this may get me what I want for now… Thanks for suggestion!

The issues you have found earlier (filed as WORDSNET-50) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.


Is there any documentation about the improvement from WORDSNET-50?

Hi Adrian,

Please refer to the LINQ Reporting Engine documentation.

Best regards,