Hyperlinks and Mailmerge Tables


#1

When creating my document, I grow a table by using the table mail-merge feature of Aspose.Word.

The problem I am having is that I need to have a hyperlink in one of the columns of the table. Right now, only the text URL of the hyperlink is written to the column. When I open the document after creation, the column shows the hyperlink as just text (not clickable). The other problem I face is that I need to display friendly text such as ("Click here to access related documents" with the underlying URL as http://www.somesite.com).

Using Aspose.Excel, this is easily handled, but in Aspose.Word I am stumped. Is there a way I can do this? My product outputs Excel and Word documents that have the same information. I must have the hyperlinks in both documents.

Cheers.


#2

Hi,

Thank you for considering Aspose.

You can customize mail merge process and do anything you need when a merge field is encountered by implementing a mail merge handler:

doc.MailMerge.MergeField += new MergeFieldEventHandler(MergeHandler);

private void MergeHandler(object sender, MergeFieldEventArgs e)

{

if (e.FieldName == "HyperlinkColumn")

{

DocumentBuilder builder = new DocumentBuilder(e.Document);

builder.MoveToMergeField(e.FieldName);

builder.Writeln("Click here to access related documents");

builder.InsertHyperlink(e.FieldValue.ToString(), e.FieldValue.ToString(), false);

}

}


#3

This worked perfectly! I added Font attributes for the color Blue and Underline. Now it looks great.

Thanks!