Click or drag to resize

Interactive Features in Excel with ExpertXls Spreadsheet Library for .NET

Using the ExpertXls Excel Library for .NET you can add hyperlinks and comments to a worksheet.

A hyperlink can be a link to a web page, a mailto link, a link to a file or folder in the local system or network or a link to a range from a worksheet. A hyperlink is represented in library by the class ExcelHyperlink. An object of this type can be obtained from the Hyperlinks collection of the ExcelWorksheet. A new object can be added to this collection using the ExcelHyperlinksCollection.AddHyperlink(ExcelHyperlinkType, ExcelRange, String) method or an existing object can be retrieved from collection by its zero based index in collection.

Code Samples

The sample code below shows how to add a hyperlink to a web page in a worksheet:

// create a hyperlink to the product website
ExcelRange websiteLinkSource = worksheet[25, 1];
string websiteUrl = "http://www.html-to-pdf.net/excel-library.aspx";
ExcelHyperlink websiteHyperlink = worksheet.Hyperlinks.AddHyperlink(ExcelHyperlinkType.Url, websiteLinkSource, websiteUrl);
websiteHyperlink.Text = "Visit product website";
websiteHyperlink.ToolTip = "Visit product website";

The code sample below shows how to add a link to a range from another worksheet:

// create a named range used as target for the link to second worksheet
ExcelNamedRange worksheetLinkTarget = workbook.NamedRanges.AddNamedRange(secondWorksheet["A1"], "SecondWorksheet");
ExcelRange worksheetLinkSource = worksheet[23, 1];
ExcelHyperlink secondWorksheetLink = worksheet.Hyperlinks.AddHyperlink(ExcelHyperlinkType.Range, worksheetLinkSource, "SecondWorksheet");
secondWorksheetLink.Text = "Go To Next Worksheet";
secondWorksheetLink.ToolTip = "Go To Next Worksheet";

A comment can be easily assigned to a cell or a range of cells using the AddComment(String) method as in the sample code below:

worksheet["A9"].AddComment("Calculate the sum of the numbers in the range C7:G7");