ExcelCell Hyperlinks

GemBox.Spreadsheet can read and write hyperlinks, but the level of support depends on the Excel file format:

  • In XLS, only HYPERLINK formula is supported.
  • In XLSX, both Hyperlink property and HYPERLINK formula are supported.
  • In PDF, ODS and HTML, only Hyperlink property is supported.

You can set hyperlink to URL or to some location in the workbook.

Screenshot

ExcelCell Hyperlinks Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using GemBox.Spreadsheet;
2using System;
3using System.IO;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
12
13        ExcelFile ef = new ExcelFile();
14        ExcelWorksheet ws = ef.Worksheets.Add("Hyperlinks");
15
16        ws.Cells["A1"].Value = "Hyperlink examples:";
17
18        ExcelCell cell = ws.Cells["B3"];
19        cell.Value = "GemBoxSoftware";
20        cell.Style.Font.UnderlineStyle = UnderlineStyle.Single;
21        cell.Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue);
22        cell.Hyperlink.Location = "http://www.gemboxsoftware.com";
23        cell.Hyperlink.IsExternal = true;
24
25        cell = ws.Cells["B5"];
26        cell.Value = "Jump";
27        cell.Style.Font.UnderlineStyle = UnderlineStyle.Single;
28        cell.Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue);
29        cell.Hyperlink.ToolTip = "This is tool tip! This hyperlink jumps to E1.";
30        cell.Hyperlink.Location = ws.Name + "!E1";
31
32        ws.Cells["E1"].Value = "Destination";
33
34        cell = ws.Cells["B8"];
35        cell.Formula = "=HYPERLINK(\"http://www.gemboxsoftware.com/GBSpreadsheet.htm\", \"Example of HYPERLINK formula\")";
36        cell.Style.Font.UnderlineStyle = UnderlineStyle.Single;
37        cell.Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue);
38
39        ef.Save("Hyperlinks.xls");
40    }
41}
1Imports GemBox.Spreadsheet
2Imports System.IO
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Dim ef As ExcelFile = New ExcelFile
12        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Hyperlinks")
13
14        ws.Cells("A1").Value = "Hyperlink examples:"
15
16        With ws.Cells.Item("B3")
17            .Value = "GemboxSoftware"
18            .Style.Font.UnderlineStyle = UnderlineStyle.Single
19            .Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue)
20            .Hyperlink.Location = "http://www.gemboxsoftware.com"
21            .Hyperlink.IsExternal = True
22        End With
23
24        With ws.Cells.Item("B5")
25            .Value = "Jump"
26            .Style.Font.UnderlineStyle = UnderlineStyle.Single
27            .Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue)
28            .Hyperlink.ToolTip = "This is tool tip! This hyperlink jumps to E1!"
29            .Hyperlink.Location = (ws.Name & "!E1")
30        End With
31
32        ws.Cells("E1").Value = "Destination"
33
34        With ws.Cells.Item("B8")
35            .Formula = "=HYPERLINK(""http://www.gemboxsoftware.com/GBSpreadsheet.htm"", ""Example of HYPERLINK formula"")"
36            .Style.Font.UnderlineStyle = UnderlineStyle.Single
37            .Style.Font.Color = SpreadsheetColor.FromName(ColorName.Blue)
38        End With
39
40        ef.Save("Hyperlinks.xls")
41
42    End Sub
43
44End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.