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.

Tue Jun 09, 2020 4:10 pm

I want mail merge using an data based on a class like this:
Could you please tell me how?
Thank you.

Code: Select all
public class MergeModel
{
   public string Name { get; set; }
   public string PhoneNumber { get; set; }
   public List<Comment> Comments { get; set; }

   public class Comment
   {
      public string CommentText { get; set; }
      public DateTime CommentDate { get; set; }
   }
}

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Wed Jun 10, 2020 6:26 am

Hello,

Thanks for your inquiry.
To mail merge nested fields, we change the code you provided to perfect the relationship of the data. Please check the code on attachment and I also attached the template file and output file for your reference. If there is any question, please feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Wed Jun 10, 2020 1:23 pm

Thank you for your code example.

So there is no way to do a mail merge with complex objects WITHOUT using DataTable and DataSet?

I want to move away from those data structures.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Thu Jun 11, 2020 3:31 am

Hello,

Thanks for your response.
Yes, doing a mail merge with complex objects requires the use of DataTable and DataSet.
Do you not want to change the class structure of the code you provide? If so, here is an alternative solution for you. You can first write the list containing MergeModel objects into an XML file, and then read the XML file into a DataSet to do the mail merge, as shown in the attached code file.

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Thu Jun 11, 2020 1:02 pm

Thank you.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Jun 12, 2020 1:00 am

Hello,

You are welcome.
Feel free to contact us if you need further assistance.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

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

Return to Spire.Doc