Mail merge with business object using reference object

I need to generate service contracts and I have problems with macros / mail merge and business object

My business object:

public class Contract
{
    public int Id { get; set; }
    public DateTime Date { get; set; }
    public string Code { get; set; }
    public Person Company { get; set; }
    public Person Invistor { get; set; }
    public List<Service> Services { get; set; }
}

    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string PostCode { get; set; }
        public string Address { get; set; }
        public string AddressNumber { get; set; }
        public string Neighborhood { get; set; }
        public string State { get; set; }
        public string City { get; set; }
    }
public class Service {
   public int Id {get;set;}
   public string Name {get;set;}
   public decimal Price {get;set;}
}


Any contracts need all properties 

Suggestion? 




Attachment: DEMO_791c6bd1.rar

3 Replies

SY Sethumanikkam Yogendran Syncfusion Team June 18, 2018 08:44 AM UTC

Hi Marcelo,

Thank you for contacting Syncfusion support.

We couldn’t extract the attached file at our end. Kindly refer the below screenshot. So, kindly attach the proper file from your end if any.


On further analyzing with the given details, we suspect that your requirement is to perform Mail merge in the input template with business objects (as mentioned). If so, you can refer the below link to know more about performing Mail merge with business objects using DocIO.
https://help.syncfusion.com/file-formats/docio/working-with-mailmerge#performing-mail-merge-with-business-objects

If you’re still facing any difficulties while achieving your requirement, then kindly provide us the following details which will be helpful for us to analyze further in line with your requirement and update you the appropriate details at the earliest.

     1. Elaborate the actual requirement with detailed description.
     2. Sample or code snippets along with input template if any.
     3. Screenshot/output documents of the expected result.

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y



MA Marcelo June 18, 2018 01:49 PM UTC

.rar ok here.

How access Company.Name in template.docx ? using referece "ReferenceObject[dot]Propertie" ?

In my example has macro using <<Company.Name>> not working, but CompanyName working...


MJ Mohanaselvam Jothi Syncfusion Team June 20, 2018 01:33 AM UTC

Hi Marcelo,

Thank you for your update.

On further analyzing with the given Word document, we have found that the merge field codes are varied with the field text in UI level.
We suspect that the field code is edited in UI level, so we suggest you to edit the field code by Right Click -> Edit Field in Microsoft Word application.

Please refer the below screenshot which illustrates field code in the UI level and exact field code in the given Word document:

 
 


To achieve your requirement using the given code example, we have modified the field code in the given template Word document as same in the UI level (
by Right Click -> Edit Field in Microsoft Word application).
Please find the modified Word document from the below link:
https://www.syncfusion.com/downloads/support/forum/138150/ze/DEMO_Modified594980677.zip


We have prepared a sample application to execute mail merge with the modified Word document using DocIO. Please find the sample from the below link:
https://www.syncfusion.com/downloads/support/forum/138150/ze/GenerateWord1032548639.zip

Regarding How access Company.Name in template.docx ? using referece "ReferenceObject[dot]Propertie" ?
In the above sample, we have performed mail merge functionality using the business objects. If you need to access the field names in the Word document, please refer the below code example to get merge field names from the document.:

 
//Gets the merge field names from the document.
string[] fieldNames = document.MailMerge.GetMergeFieldNames() 

Regarding In my example has macro using <<Company.Name>> not working, but CompanyName working:
In the above sample application, “<<Company.Name>>” field is merged with their value using DocIO properly at our end.
If you are still facing same problem means, we suspect that the problem might be due to code snippets used at your end. So, could you please provide us the modified sample of above along with complete code snippets and output document generated at your end. Also, provide us the details on product version which used at your end. Thereby we will analyze further on your scenario and provide you the appropriate solution at the earliest.


Please refer the below UG documentation links to know more about working with mail merge using DocIO:
Working with MailMerge
Performing Mail merge with business objects


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


Loader.
Up arrow icon