This is a migrated thread and some comments may be shown as answers.
Using Mergefields to fill a table
6 Answers 97 Views
This is a migrated thread and some comments may be shown as answers.
Pieter
Top achievements
Rank 1
Pieter asked on 21 May 2016, 09:16 PM

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; }
}

6 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 25 May 2016, 07:02 AM
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.
0
Pieter
Top achievements
Rank 1
answered on 25 May 2016, 07:24 AM

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)

0
Mihail
Telerik team
answered on 27 May 2016, 07:52 AM
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.
0
Pieter
Top achievements
Rank 1
answered on 27 May 2016, 08:28 AM

Ok, Thanks for the info.

I will wait for this feature then.

0
Ahsan
Top achievements
Rank 1
answered on 20 Apr 2020, 04:23 PM

is this Mergefield to fill a table is available ? or any play around?


0
Tanya
Telerik team
answered on 22 Apr 2020, 09:06 AM

Hello Ahsan,

The feature is still not implemented. Please, make sure to vote for its implementation using the request on our public portal. With the current implementation, I cannot suggest an approach that would allow you to customize the behavior in a way that would achieve the desired result.

Regards,
Tanya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Asked by
Pieter
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Pieter
Top achievements
Rank 1
Ahsan
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or