I am having an issue when i have a data source that has child tables associated with it. The issue occurs when the parent data source has 2 rows and parent row 1 has zero child rows but parent row 2 has two child rows.
- Parent Row 1
- Parent Row 2
When I get start merging “child row 2” I have some custom code that will insert html into the merge field. It does this with code like this in the FieldMerging callback.
What happens is the “MoveToMergeField” does not position to the correct point in the document for the child row 2. Instead it will position to the child table under Parent Row 1. And, to make it even more difficult to understand the actual issue, what ends up being inserted at the merge field for child row 2 is the html mark up for the field.
The other thing to note about this scenario is that I have multiple data sources that are being merged into the word template. So the code does not remove unused regions until the last data source is merged into the template. i.e.
doc.MailMerge.CleanupOptions = Aspose.Words.Reporting.MailMergeCleanupOptions.RemoveUnusedRegions;
I believe this is the real source of the problem because the MoveToMergeField statement actually ends up moving to the cursor to the child table under Parent Row 1 instead of the child table under parent row 2.
I have include a sample program that reproduces this issue. Can you help me understand how to properly position to the merge field in this type of scenario.
As a side note, the solution cannot be always have a child row under parent row 1 because I do not have child rows in some scenarios and also I do not want that table region to show up in the document when there are not any child rows for a given parent.