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:
https://reference.aspose.com/words/java/com.aspose.words/ifieldmergingcallback/
https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#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 {HYPERLINK { MERGEFIELD realValue \* 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:
https://reference.aspose.com/words/java/com.aspose.words/ifieldmergingcallback/
https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#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,