MailMerge into ONE Table

2 posts, 0 answers
  1. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 04 Mar 2013 Link to this post


    What I want to achieve is to MailMerge a datasource into one single table via Doc API. I have already succeeded in creating a table, add a merge field to each cell and do a MailMerge, but this results in a single table row per record each with two paragraphs between them. Here is my code:

                Table table = new Table();
                TableRow row1 = new TableRow();
                TableCell cell1 = new TableCell();
                Paragraph p1 = new Paragraph();
                FieldRangeStart start = new FieldRangeStart();
                FieldRangeEnd end = new FieldRangeEnd();
                end.Start = start;
                start.Field = new MergeField() { PropertyPath = "FirstName" };
                Span s1 = new Span();
                s1.Text = "{MERGEFIELD FirstName}";
    ... (add more table cells)
                doc2.MailMergeDataSource.ItemsSource = ExamplesDataContext.Employees;
                doc.InsertFragment(new DocumentFragment(doc2.MailMerge(false)));

  2. Petya
    Petya avatar
    990 posts

    Posted 07 Mar 2013 Link to this post

    Hi Neils,

    The scenario you are trying to achieve is somewhat strange.

    Generally, when executing a mail merge, each record is placed in a new section or is at least separated from the previous (in custom scenarios). That's the default behavior and is the expected one.

    What is more, the logic you've implemented inserts a fragment that contains a whole table, so it is only natural for each table to be separate. Generally, RadDocument's structure does not allow adjacent tables, so they cannot be added without the additional paragraphs. Nonetheless, implementing a mail merge as the one explained is not one of the scenarios supported out of the box and you can verify the same behavior if you try it in MS Word.

    What I believe will much better suit your need is to build your table with the actual values instead. As you are building your document from code, you can simply add all records to a table, putting each in a single row, and add to the RadDocument this table instead.

    I hope this helps!

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top