We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Update .doc/.docx document mailmerge field

Good day,

I'm trying to use a .doc/.docx as a template for mail merge and then convert it to PDF.

It is possible to force the behavior of CTRL+A, F9 (Update all fields) before doing the conversion or during mailmerge or that the mailmerge output of syncfusion to be the final result of the mailmerge.

Exemple : 

Word Document : Field :
    {IF "{MERGEFIELD Test1}" = "Answer1" "" "{IF "{MERGEFIELD Test2}" = "Answer2" "Anwser3" "Answer4"}"} 

Output : if (Test1 = "Answer2" and Test2 !="Answer1")
    {IF "Answer2" = "Answer1" "" "{IF "Answer1 = "Answer2" "Anwser3" "Answer4"}"} and show nothing since not updated.
    after manually updating all field (CTRL+A, F9) it show "Answer4".

Expected Output 
    {IF "Answer2" = "Answer1" "" "{IF "Answer1" = "Answer2" "Anwser3" "Answer4"}"} and show "Answer4"
    "Answer4" (like if the mergefield didn't have a if condition).

Thank you in advance for your time.




Mail merge done with : 

            var oDocTemplate = new WordDocument(docFilePath);

            oDocTemplate.MailMerge.RemoveEmptyParagraphs = true;
            oDocTemplate.MailMerge.RemoveEmptyGroup = true;
            oDocTemplate.MailMerge.ClearFields = true;

            oDocTemplate.Save(saveFilePath, FormatType.Docx);

Conversion done with 

            var wordDoc = new WordDocument(docFilePath);
            var converter = new DocToPDFConverter();
            var pdfDoc = converter.ConvertToPDF(wordDoc);

1 Reply

SV Sarathkumar V Syncfusion Team June 24, 2014 08:44 AM UTC

Hi Simon,

Thank you for using Syncfusion products.

Update fields behavior (CTRL+A, F9) of MS Word is already implemented in DocIO by calling the UpdateDocumentFields() method. MailMerge.Execute() will performs replacements of every merge field in the document with data from the data source. If you call the UpdateDocumentFields() method before executing the mail merge the fields are updated using existing values. After executing the mailmerge, DocIO uses the populated values to update the fields.

In your given nested if field scenario we have found the issue in updating field result and we have forwarded this to our developer for further analysis. We have created a new incident #126574 for further follow ups. Kindly follow the incident #126574 to get resolved the mentioned issue.

Incident Link:

Please let us know if you have any questions.


Live Chat Icon For mobile
Up arrow icon