Inserting Hyperlinks Dynamically

Using GroupDocs.Assembly, you can insert hyperlinks to your reports dynamically using link tags. The syntax of a link tag is defined as follows:

<<link [uri_expression][display_text_expression]>>

Here, uri_expression defines URI for a hyperlink to be inserted dynamically. This expression is mandatory and must return a non-empty value. In turn, display_text_expression defines text to be displayed for the hyperlink. This expression is optional. If it is omitted or returns an empty value, then during runtime, a value of uri_expression is used as display text as well. Values of both uri_expression and display_text_expression can be of any types. During runtime, Object.ToString() is invoked to get textual representations of these expressions’ values, which is useful for expressions of types like Uri, for example, while building a report, uri_expression and display_text_expression are evaluated and their results are used to construct a hyperlink that replaces the corresponding link tag then.

You can also insert links to bookmarks to your reports dynamically using link tags. The syntax of a link tag is defined as follows:

<<link [uri_or_bookmark_expression][display_text_expression]>>

Here, uri_or_bookmark_expression defines URI or the name of a bookmark within the same document for a hyperlink to be inserted dynamically. This expression is mandatory and must return a non-empty value.In turn, display_text_expression defines text to be displayed for the hyperlink. This expression is optional. If it is omitted or returns an empty value, then during runtime, a value of uri_or_bookmark_expression is used as display text as well.

For Spreadsheet documents, behavior of link tags is changed as follows. If an expression defined within a link tag is evaluated to a cell or cell range reference during runtime, then the tag is replaced with a link to the corresponding cell or cell range.

The following table describes supported formats of cell and cell range references.

DescriptionFormatExample
Reference to a cell within the same worksheetcell_nameA1
Reference to a cell in another worksheetworksheet_name!cell_nameSheet1!A1
Reference to a cell range within the same worksheetstart_cell_name:end_cell_nameA1:B2
Reference to a cell range in another worksheetworksheet_name!start_cell_name:end_cell_nameSheet1!A1:B2

Following is sample syntax, If the insertion of the link to cell A1 is required :

<<link ["A1"] ["Home"]>>

For Presentation documents, behavior of link tags is changed as follows. If an expression defined within a link tag is evaluated to a “SlideN” value, where N is a one-based index of a slide within the same Presentation document, then the tag is replaced with a link to the corresponding slide during run time.

See the example of the syntax as follows:

<<link ["Slide1"] ["Home"]>>

Code Examples and Templates

Word Processing Documents

Download

Presentation Documents 

Download

Spreadsheet Documents

Download

Email Documents 

Download