Mail merge region for multiple rows

We’d like to use the MailMerge.ExecuteWithRegions method to repeat 2 rows in a table, without programmatically manipulating the table (since the template doc should be able to change).
The ideal would be to repeat 2 rows within the table itself. However, if the TableStart / TableEnd fields are not in the same row, we would get this error: “Mail merge region is badly formed. TableStart and TableEnd should be in the same section, soame table row or same table cell.”. It would therefore be a nice feature to allow TableStart/TableEnd to be in different rows.
Taking another approach and placing TableStart and TableEnd around a small table containing 2 rows only, causes unwanted paragraph breaks between the tables (they should be flush against each other) since it seems to be impossible to position the TableStart/TableEnd fields to the immediate left/right of the table in Word itself.
We would appreciate any suggestions.

Hi
Thanks for your request. You can place TableStart and TableEnd fields outside the table.

«TableStart:table»

«Field1» «Field2» «Field3» «Field4» «Field5»
«Field6» «Field7» «Field8» «Field9» «Field10»

«TableEnd:table»

But then you should programmatically remove empty paragraphs between tables after executing mail marge. See the following example.

Document doc = new Document(@"061_89177_HannesRSA\in.doc");
doc.MailMerge.ExecuteWithRegions(table1);
NodeCollection nodes = doc.GetChildNodes(NodeType.Paragraph, true);
ArrayList list = new ArrayList();
foreach (Node node in nodes)
{
    Paragraph par = (node as Paragraph);
    if (par.Range.Text == "\r")
    {
        list.Add(par);
    }
}
foreach (Paragraph par in list)
{
    par.Remove();
}
doc.Save(@"061_89177_HannesRSA\out.doc");

I hope that it will help you.

Hi Vitaly,
Thanks, this should work for what we are doing.

This feature is now available in this .NET update and in this Java update. You can now avoid empty paragraphs in repeating regions in this version by setting RemoveEmptyParagraphs to true.

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