Using Mergefields to fill a table

5 posts, 0 answers
  1. Pieter
    Pieter avatar
    3 posts
    Member since:
    May 2016

    Posted 21 May Link to this post

    Hello,

    I have some code to import a Word-document with MergeFields, than I MailMerge it with some data end export it to a new document.

    This works fine, but I also want to fill a table in the document. How can this be done?

    I was trying something like this, but this doesn't work ...

    Thanks for any help you guys can give!

     

    using System.Collections.Generic;
    using System.IO;
    using Telerik.Windows.Documents.Flow.Model;
    using Telerik.Windows.Documents.Flow.FormatProviders.Docx;

    public class ProccessDocument
    {
        public ProccessDocument()
        {
            RadFlowDocument importDocument = new RadFlowDocument();

            DocxFormatProvider providerIn = new DocxFormatProvider();
            using (Stream input = File.OpenRead("import.docx"))
            {
                importDocument = providerIn.Import(input);
            }

            RadFlowDocument exportDocument = importDocument.MailMerge(GetData());

            DocxFormatProvider providerUit = new DocxFormatProvider();
            using (Stream output = File.OpenWrite("export.docx"))
            {
                providerUit.Export(exportDocument, output);
            }
        }

        private List<Schedule> GetData()
        {
            return new List<Schedule>()
                {
                    new Schedule()
                    {
                        Name = "John",

                        Items = new List<Item>()
                        {
                            new Item() { Date = "11/5/2016", Subject = "Soccer training" },
                        }
                    },
                    new Schedule()
                    {
                        Name = "Debby",

                        Items = new List<Item>()
                        {
                            new Item() { Date = "10/5/2016", Subject = "Swimming" },
                            new Item() { Date = "12/5/2016", Subject = "Dancing" },
                            new Item() { Date = "15/5/2016", Subject = "Music" },
                        }
                    },
                };
        }
    }

    public class Schedule
    {
        public string Name { get; set; }
        public List<Item> Items { get; set; }
    }

    public class Item
    {
        public string Date { get; set; }
        public string Subject { get; set; }
    }

  2. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 25 May Link to this post

    Hello Pieter,

    Filling table with data could be done only if the table is already populated with the corresponding rows, cells and merge fields.

    If you need to add additional rows using a template row, then this should be done separately from the mail merge functionality. We have a feature request that we call "Nested Mail Merge" which should allow such scenarios. However it is still not implemented. If you are interested in this feature you could vote and subscribe to the item for status changes.

    Regards,
    Mihail
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. Pieter
    Pieter avatar
    3 posts
    Member since:
    May 2016

    Posted 25 May in reply to Mihail Link to this post

    Thanks for the reply.

    Is there perhaps a way to put a

    whole table in 1 MergeField (I read something about CustomMergeFields)?

    I rather program different kinds of tables to specify every table I need, instead of making word templates with 100 rows and 10 columns, filled with Mergefields (which I need to define 1 by 1)

  4. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 27 May Link to this post

    Hello Pieter,

    I am afraid that the functionality to return a table from a merge field is not available yet as it is part of the Nested Mail Merge feature.

    Regards,
    Mihail
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. Pieter
    Pieter avatar
    3 posts
    Member since:
    May 2016

    Posted 27 May in reply to Mihail Link to this post

    Ok, Thanks for the info.

    I will wait for this feature then.

Back to Top