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

Free Support Forum - aspose.com

IMailMergeSource GetChildDataSource question

Hi,


I have attached an example to assist with my explanation.
As you can see the first region is called “Person”, it’s only child region is “Program”. Why when Aspose.Words is finished processing the first region and then sees the new StartTable for Program, does it call the GetChildDataSource method with “Person” as the tableName parameter? Shouldn’t it pass on “Program” as the tableName?

Thanks,
Adam

Hi Adam,


Thanks for your inquiry. The child region in your template document seems incorrect (please see attached screenshot to spot the corrections). Secondly, please find below the description of GetChildDataSource method:

The Aspose.Words mail merge engine invokes this method when it encounters a beginning of a nested mail merge region.

When the Aspose.Words mail merge engines populates a mail merge region with data and encounters the beginning of a nested mail merge region in the form of MERGEFIELD TableStart:TableName, it invokes GetChildDataSource on the current data source object. Your implementation needs to return a new data source object that will provide access to the child records of the current parent record. Aspose.Words will use the returned data source to populate the nested mail merge region.

Below are the rules that the implementation of GetChildDataSource must follow.

If the table that is represented by this data source object has a related child (detail) table with the specified name, then your implementation needs to return a new IMailMergeDataSource object that will provide access to the child records of the current record. An example of this is Orders / OrderDetails relationship. Let’s assume that the current IMailMergeDataSource object represents the Orders table and it has a current order record. Next, Aspose.Words encounters “MERGEFIELD TableStart:OrderDetails” in the document and invokes GetChildDataSource. You need to create and return a IMailMergeDataSource object that will allow Aspose.Words to access the OrderDetails record for the current order.

If this data source object does not have a relation to the table with the specified name, then you need to return a IMailMergeDataSource object that will provide access to all records of the specified table.

If a table with the specified name does not exist, your implementation should return null.

I hope this helps.

Best regards,