MailMerge using an IF statement where one result contains a hyperlink

Hello,

I'm trying to perform a mail merge on a Word document with an IF statement, where one of the possible results has a hyperlink. For example:

{ IF { MERGEFIELD FieldName } = "True" "No need to log in" "Click { HYPERLINK "https://example.com/Account/Login" } to log in" }

The C# code I'm using is:

public void PerformMailMerge(WordDocument document, string[] names, string[] values)
{
document.MailMerge.RemoveEmptyParagraphs = true;
document.MailMerge.Execute(names, values);
document.UpdateDocumentFields();
}

The result of this if FieldName != "True" is:

Click here​ to log in"

That is, the text has a spurious double-quotes at the end of the line.

I've been able to get round this by putting "Click { HYPERLINK "https://example.com/Account/Login" } to log in" in a separate file and using:

{ IF { MERGEFIELD FieldName } = "True" "No need to log in" "{ INCLUDETEXT "TextWithLink.docx" }"

However, this adds 2 empty paragraphs under the text generated by the merge.

Would you be able to help me either get rid of the trailing double quotes in the first case, or the empty paragraphs in the second case?

Kind regards,

Barney Walton


UPDATE: I've updated Syncfusion.DocIO.AspNet.Mvc5 to version 21,2,4 (I was using v18.3.0.35 before) and now the output if I use the second method I describe above is:

Click here

i.e. the text after the link is missing.

With the first method I describe above, the result is the same.

Kind regards,

Barney


1 Reply

SB Suriya Balamurugan Syncfusion Team May 15, 2023 05:58 PM UTC

Hi Barney,

We have tried to reproduce the reported problems (case 1 and case 2) using the given IF field statement and code snippet.

But we are facing some other different results instead of the reported issues (both cases) at our end using the given IF field statement and code snippet in your mentioned product version (v18.3.0.35) and the latest release version (v21.2.4).

Regarding – Case 1: the text has a spurious double-quotes at the end of the line

Input

Output generated at our end


Regarding – Case 2: adds 2 empty paragraphs under the text generated by the merge

Input

Output generated at our end


For your reference, we have attached the sample application which we tried to reproduce the reported problem.

Note: Please find the input Word document in the “Data” folder of the attached sample application.


Could you please try the attached sample application on your end and provide us confirmation whether you are facing this same problem at your end.

If this is not your reported problem, then
kindly share us the below details from your end, which will be helpful to reproduce the exact issue at our end.
  1. Modified sample of the attached sample.
  2. Input Word documents to reproduce the exact reported issue.
  3. Screenshots of the issue.

Based on the above details, we will check and provide you appropriate solution at the earliest.

Regards,
Suriya Balamurugan.


Attachment: Executemailmerge_577c7c8f.zip

Loader.
Up arrow icon