Apply Mergefield and replace by another mergefield

Hello,

Is it possible to replace a mergefield by another mergefield when executing it ?
My goal is to show the user the result of the mergefield but to keep the ability to do a mergefield later.

Something like :

string field_name = "mergield_code"
string[] fieldNames = {field_name}

field_value = new MergeField(field_name, "New field value")
string[]fieldValues = {field_value}

document.MailMerge.Execute(fieldNames, fieldValues)

Thanks,
Tuan

3 Replies

MJ Mohanaselvam Jothi Syncfusion Team January 15, 2021 01:37 PM UTC

Hi Tuan,

Thank you for contacting Syncfusion support.

We have prepared the sample for your requirement and it can be downloaded from the below link, which also contain output document generated at our end:
https://www.syncfusion.com/downloads/support/forum/161479/ze/SampleAndOutput38066858
Note: You can find the input template in “Data” folder from the above sample.

In the above sample, we have done the below things:
  1. Loads the template Word document.
  2. Execute mail merge.
  3. Using MergeField event, get the index of merge field and paragraph.
  4. In the event handler, get the field value to consider for new merge field name and set empty to existing merge field values.
  5. Insert new merge field in the same index of paragraph.
  6. Saves the Word document.

If the above suggestion doesn’t meet your end requirement means, kindly share us the input template and expected output Word document which created by manually. Thereby, we will check on your requirement and will share the appropriate solution.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



TA Tuan Ardouin May 3, 2021 02:26 PM UTC

Hello,

Thank you for this sample and sorry for not responding.

In your example you used 

paragraph.AppendField(fieldName, FieldType.FieldMergeField);

This add a mergefield to the document but with a code equal to the label. Is it possible to have a control over the MERGEFORMAT when inserting an element of type FieldMergeField.

My final goal is to always keep the code of the mergefield, and change only the label.

Thank you,
Tuan


LB Lokesh Baskar Syncfusion Team May 4, 2021 09:58 AM UTC

Hi Tuan,

Thank you for your update.

From the given details, we have not found the complete details about your end requirement. So, could you please share us the expected output document (edited manually) and more details about the requirement. Thereby, we will check the feasibilities to meet your requirement and will provide you the appropriate solution.

Please let us know if you have any other questions.

Regards, 
Lokesh B 


Loader.
Up arrow icon