Merge Field with hyperlink

Hi,

I have created document with hyperlink with mergefield:
image.png (34.4 KB)
When opened in Aspose and saved as docs this is how it looks:
image.png (33.1 KB)

This is the example file:
file.docx (15.9 KB)

Code used:

var saveOptions = new OoxmlSaveOptions
{
    SaveFormat = SaveFormat.Docx
};

var loadOptions = new LoadOptions(LoadFormat.Docx, "", "");

var document = new Document("file.docx", loadOptions);
document.JoinRunsWithSameFormatting();

Console.WriteLine(document.Compliance.ToString());
Console.WriteLine(document.OriginalLoadFormat.ToString());

document.Save("out.docx", saveOptions);

When merge field is merged in first document it works correctly:
image.png (85.0 KB)

document.MailMerge.MergeWholeDocument = true;
document.MailMerge.TrimWhitespaces = false;
document.MailMerge.Execute(new string[] { "website" }, new object[] { "https://forum.aspose.com/" });

document.Save("out.pdf", SaveFormat.Pdf);

Is there some setting I am missing?
If the hyperlink with mergefield is the fist thing in document it works correctly.

Thanks

@vktchrzascik

We have tested the scenario using the latest version of Aspose.Words for .NET 21.4 and have not found any issue with mail merge.

If you re-saving your document using MS Word, the mail merge field is also lost. Could you please share some more detail about the issue that you are facing with re-saving document? We will then guide you accordingly.

Yes the document is opened and resaved the mergefield is broken. When doing it in word it works ok.

document = new Document("file.docx", loadOptions);
document.JoinRunsWithSameFormatting();

document.Save("out.docx", saveOptions);
document = new Document("out.docx", loadOptions);
document.MailMerge.MergeWholeDocument = true;
document.MailMerge.TrimWhitespaces = false;
document.MailMerge.Execute(new string[] { "website" }, new object[] { "https://forum.aspose.com/" });
document.Save("out.pdf", SaveFormat.Pdf);

@vktchrzascik

We have tested the scenario using the latest version of Aspose.Words for .NET 21.4 with following code example and have not found the shared issue. So, please use Aspose.Words for .NET 21.4. You do not need to save the document to DOCX and load it again.

var loadOptions = new LoadOptions(LoadFormat.Docx, "", "");

var document = new Document(MyDir + "file.docx", loadOptions);
document.JoinRunsWithSameFormatting();

var saveOptions = new OoxmlSaveOptions
{
    SaveFormat = SaveFormat.Docx
};

document.MailMerge.MergeWholeDocument = true;
document.MailMerge.TrimWhitespaces = false;
document.MailMerge.Execute(new string[] { "website" }, new object[] { "https://forum.aspose.com/" });

document.Save(MyDir + "out.pdf", SaveFormat.Pdf); 

Loading twice represents some business process. We merge data into template (replacing some texts), save it to docx. User can change the document manually and later we use mail merge. So saving it is necessary. The merge field is working if it is first thing in the document.

Can you check if saving it breaks it for you?

@vktchrzascik

The mail merge field does not appear in output DOCX after re-saving document using MS Word and Aspose.Words. However, we have logged this problem in our issue tracking system as WORDSNET-22185 for investigation. We will inform you via this forum thread once there is any update available on it.

Thanks

I have tried re-saving document using MS Word (Versions 2102) and it doesn’t break the fields.

How MS Word breaks field?

@vktchrzascik

Please check the attached image and Word document that is re-saved using MS Word 2019.
mail merge field.png (69.4 KB)
re-saved using ms word 2019.docx (15.1 KB)

The mail merged field «website» is simple text.

The issues you have found earlier (filed as WORDSNET-22185) have been fixed in this Aspose.Words for .NET 21.6 update and this Aspose.Words for Java 21.6 update.