Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Feb 24, 2021 3:05 pm

Hi, so I copied the code from the tutorial "Creating Mail Merge for a group in C#" but it is not working for me


Code: Select all
class Program
    {
        static void Main(string[] args)
        {
            Product p1 = new Product(1, "Software", "Spire.Doc", "$799", "E-iceblue", "April 28th,2018");
            Product p2 = new Product(2, "Software", "Spire.PDF", "$599", "E-iceblue", "September 15th,2017");

            List<Product> list = new List<Product>();
            list.Add(p1);
            list.Add(p2);

            Document document = new Document("ProductsList.docx");

            MailMergeDataTable table = new MailMergeDataTable("Products", list);
            document.MailMerge.ExecuteGroup(table);

            document.SaveToFile("Output.docx");
            System.Diagnostics.Process.Start("Output.docx");
        }
    }


    public class Product
    {
        public Product(int number, string type, string name, string price, string vendor, string expirydate)
        {
            this.number = number;
            this.type = type;
            this.name = name;
            this.price = price;
            this.vendor = vendor;
            this.expirydate = expirydate;
        }

        int number;
        string type, name, price, vendor, expirydate;
    }

timo.loehr
 
Posts: 2
Joined: Tue Jan 12, 2021 3:25 pm

Thu Feb 25, 2021 2:20 am

Hello,

Thanks for your inquiry.
Based on our internal merging mechanism, the "Product" Class and its attributes have to be public, please refer to the following modified code to try again. Any question, just feel free to contact us.
Code: Select all
    class Program
    {
        static void Main(string[] args)
        {
            Product p1 = new Product(1, "Software", "Spire.Doc", "$799", "E-iceblue", "April 28th,2018");
            Product p2 = new Product(2, "Software", "Spire.PDF", "$599", "E-iceblue", "September 15th,2017");

            List<Product> list = new List<Product>();
            list.Add(p1);
            list.Add(p2);

            Document document = new Document("ProductsList.docx");

            MailMergeDataTable table = new MailMergeDataTable("Products", list);
            document.MailMerge.ExecuteGroup(table);

            document.SaveToFile("Output.docx");
            System.Diagnostics.Process.Start("Output.docx");
        }
    }


    public class Product
    {
        public Product(int number, string type, string name, string price, string vendor, string expirydate)
        {
            this.number = number;
            this.type = type;
            this.name = name;
            this.price = price;
            this.vendor = vendor;
            this.expirydate = expirydate;
        }

        public int number { get; set; }
        public string type { get; set; }
        public string name { get; set; }
        public string price { get; set; }
        public string vendor { get; set; }
        public string expirydate { get; set; }
    }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Mar 02, 2021 7:06 am

Hello,

Greetings from E-iceblue!
Has your issue been resolved? Thanks in advance for your feedback!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc