We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Is it possible to make hyperlink inside MailMerge

I need to insert into cell dynamic text and make this text as hyperlink.

Is it possible to make this using MailMerge?

Hello

Thanks for your request. I think you can try using iFieldMergingCallback and InsertHyperlink method to insert a hyperlink into the document during MailMerge. Please see the following links to learn more:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/ifieldmergingcallback.html

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/documentbuilder.html#insertHyperlink(java.lang.String, java.lang.String, boolean)

Best regards,

Thanks. I’ll look through that links.

But I found out one more way to make this.
First I made the dynamic text feild.
After that I selected this text and make standart hyperlink. After that I use ALT+F9 (Office 2010) and modified the HYPERLINK code like
<span style=“font-size:10.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:RU;mso-fareast-language:
RU;mso-bidi-language:AR-SA”>{HYPERLINK {<span style=“font-size:10.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:RU;mso-fareast-language:
RU;mso-bidi-language:AR-SA”>MERGEFIELD <span lang=“EN-US” style=“font-size:10.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:EN-US;mso-fareast-language:
RU;mso-bidi-language:AR-SA”>realValue.<span style=“font-size:10.0pt;
font-family:“Times New Roman”,“serif”;mso-fareast-font-family:“Times New Roman”;
mso-ansi-language:RU;mso-fareast-language:RU;mso-bidi-language:AR-SA;
mso-no-proof:yes”>hosting<span lang=“EN-US” style=“font-size:10.0pt;
font-family:“Times New Roman”,“serif”;mso-fareast-font-family:“Times New Roman”;
mso-ansi-language:EN-US;mso-fareast-language:RU;mso-bidi-language:AR-SA;
mso-no-proof:yes”>URL<span lang=“EN-US” style=“font-size:10.0pt;
font-family:“Times New Roman”,“serif”;mso-fareast-font-family:“Times New Roman”;
mso-ansi-language:RU;mso-fareast-language:RU;mso-bidi-language:AR-SA”> <span lang=“EN-US” style=“font-size:10.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:EN-US;mso-fareast-language:
RU;mso-bidi-language:AR-SA”> <span style=“font-size:10.0pt;font-family:“Times New Roman”,“serif”;mso-fareast-font-family:
“Times New Roman”;mso-ansi-language:RU;mso-fareast-language:RU;mso-bidi-language:
AR-SA”>* MERGEFORMAT} }
In this way I have taken that I need.

Hi

It is perfect, that you already found solution. Please let me know in case of any issues. I will be glad to help you.

Best regards,

AndreyN:

Hello

Thanks for your request. I think you can try using iFieldMergingCallback and InsertHyperlink method to insert a hyperlink into the document during MailMerge. Please see the following links to learn more:

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/ifieldmergingcallback.html

http://www.aspose.com/documentation/java-components/aspose.words-for-java/com/aspose/words/documentbuilder.html#insertHyperlink(java.lang.String, java.lang.String, boolean)

Best regards,

So, in another topic we have found that word is breaking the document structure if I try make some dinamic hyperlink.
How can I do this using FieldMergingCallback?
How can I get access to aonother property of MergingObject inside
public void fieldMerging(FieldMergingArgs fieldMergingArgs) throws Exception
?

Hello

Thanks for your request. Please try using the following code:

Document doc = new Document("C:\\Temp\\in.docx");

// Add a handler for the MergeField event.

doc.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertHuperlink());

// Execute mail merge.

doc.getMailMerge().execute(new String[] { "hyperlink" }, new String[] { "http:\\google.com" });

// Save resulting document with a new name.

doc.save("C:\\Temp\\out.docx", SaveFormat.DOCX);

private static class HandleMergeFieldInsertHuperlink implements IFieldMergingCallback

{

///

/// This is called when merge field is actually merged with data in the document.

///

public void /*IFieldMergingCallback.*/fieldMerging(FieldMergingArgs e) throws Exception

{

// Insert the Hyperlink for this merge field using DocumentBuilder.

DocumentBuilder builder = new DocumentBuilder(e.getDocument());

builder.moveToMergeField(e.getDocumentFieldName());

builder.insertHyperlink("myLink", (String)e.getFieldValue(), false);

}

public void /*IFieldMergingCallback.*/imageFieldMerging(ImageFieldMergingArgs e) throws Exception

{

// Do nothing.

}

}

Please see the attached input and output documents.

Best regards,