Create dynamic table and insert data dynamically

Hi Team,

I want to insert a dynamic table into an existing template.

  1. The number of tables created may vary.
  2. The number of rows in each table may also vary.
  3. We should be able to populate data in the tables dynamically.

Could you please suggest the steps needs to be taken for the same.

@isha0705,

I believe, you can meet these requirements by using the Mail Merge with Regions functionality of Aspose.Words.

Hi, Thanks for your quick response.

As we are using LINQ Reporting Engine in our current application and not using Mail Merge and Reporting, will it not be a problem to use the mail merge code and mix two types of code?

Could you please give some suggestion on same or provide some code snippet if you feel that it will work.
Thanks.

@isha0705,

Yes, there should not be a problem when using LINQ reporting engine along with standard Mail Merge with Regions. Different code examples can be found in the following sections of documentation:

Mail Merge and Reporting
LINQ Reporting Engine

@isha0705,

Please also note that the LINQ Reporting Engine is also capable to serve such simple scenario on its own. For example, please check the following code snippet and attached template documents (Docs.zip (36.8 KB)):

public class Person
{
    public string Name { get; set; }
    public List<Person> Children { get; set; }
}

private static List<Person> GetPersons()
{
    return new List<Person>
        {
            new Person
            {
                Name = "Jane Doe",
                Children = new List<Person>
                {
                    new Person { Name = "Ann Doe" },
                    new Person { Name = "John Doe" }
                }
            },
            new Person
            {
                Name = "John Smith",
                Children = new List<Person>
                {
                    new Person { Name = "Tom Smith" }
                }
            }
        };
}

public void DynamicallyShowAndFillTableDependingOnCondition()
{
    Document document = new Document(MyDir + "DynamicallyShowAndFillTableDependingOnCondition.docx");

    ReportingEngine engine = new ReportingEngine();
    engine.Options |= ReportBuildOptions.RemoveEmptyParagraphs;
    engine.BuildReport(document, GetPersons(), "persons");

    document.Save(MyDir + "DynamicallyShowAndFillTableDependingOnCondition Out.docx");
}

public void DynamicallyFillMultipleTablesDependingOnCollectionItems()
{
    Document document = new Document(MyDir + "DynamicallyFillMultipleTablesDependingOnCollectionItems.docx");

    ReportingEngine engine = new ReportingEngine();
    engine.Options |= ReportBuildOptions.RemoveEmptyParagraphs;
    engine.BuildReport(document, GetPersons(), "persons");

    document.Save(MyDir + "DynamicallyFillMultipleTablesDependingOnCollectionItems Out.docx");
}

Hope, this helps.

Thanks for your help :slightly_smiling_face:

A post was split to a new topic: Dynamically Show & Fill a Single or Multiple Tables depending on Condition or Collection Items | C# LINQ Reporting