### Hyperlinks in cells.

Hyperlinks can be added to cells using the `ExcelRangeBase.SetHyperlink` method or the `ExcelRangeBase.Hyperlink` property. You can set the hyperlink using the standard .NET Uri class or the extended `ExcelHyperLink` class.

For example:

```csharp
worksheet.Cells["A1"].SetHyperlink(worksheet.Cells["G12"], "Link to cell G12..");
worksheet.Cells["A2"].Hyperlink = new Uri("https://epplussoftware.com", UriKind.Absolute);

var hyperLink = new ExcelHyperLink("https://samples.epplussoftware.com/HtmlExport/", UriKind.Absolute);
hyperLink.Display = "EPPlus HTML Export Sample Website...";
hyperLink.ToolTip = "Follow this link to the EPPlus HTML Export sample website";
worksheet.Cells["A3"].Hyperlink = hyperLink;
```

```vbnet
worksheet.Cells("A1").SetHyperlink(worksheet.Cells("G12"), "Link to cell G12..")
worksheet.Cells("A2").Hyperlink = New Uri("https://epplussoftware.com", UriKind.Absolute)

Dim hyperLink = New ExcelHyperLink("https://samples.epplussoftware.com/HtmlExport/", UriKind.Absolute)
hyperLink.Display = "EPPlus HTML Export Sample Website..."
hyperLink.ToolTip = "Follow this link to the EPPlus HTML Export sample website"
worksheet.Cells("A3").Hyperlink = hyperLink
```

To style the hyperlinks you can create the named style for the Hyperlinks.

```csharp
var namedStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink");
namedStyle.BuildInId = 8; //This is the id for the build in hyper link style.
```

```vbnet
Dim namedStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink")
namedStyle.BuildInId = 8 'This is the id for the build in hyper link style.
```

```csharp
var namedStyle = package.Workbook.Styles.CreateNamedStyle("Followed HyperLink");
namedStyle.BuildInId = 9; //This is the id for the build in followed hyper link style.
```

```vbnet
Dim namedStyle = package.Workbook.Styles.CreateNamedStyle("Followed HyperLink")
namedStyle.BuildInId = 9 'This is the id for the build in followed hyper link style.
```

To set the style for the hyperlink, set the `StyleName` of the cells to the created named style.

```csharp
worksheet.Cells["A1:A3"].StyleName = "HyperLink";
```

```vbnet
worksheet.Cells("A1:A3").StyleName = "HyperLink"
```

### Drawings as Hyperlinks

**To set the style for the hyperlink, set the `StyleName` of the cells to the created named style.**

```csharp
worksheet.Cells["A1:A3"].StyleName = "HyperLink";
```

```vbnet
worksheet.Cells("A1:A3").StyleName = "HyperLink"
```

### Drawings as Hyperlinks

If you want a hyperlink that is not connected to a cell, you can add a drawing with a hyperlink.  
In this sample we add a shape that is positioned absolute, to keep its position when rows or columns are hidden:

```csharp
//Add a drawing with a HyperLink to the statistics sheet.
//We add the hyperlink as a drawing here, as we don't want it to move when we expand and collapse rows.
var hyperLink =ws.Drawings.AddShape("HyperLink", eShapeStyle.Rect);            
hyperLink.Hyperlink = new ExcelHyperLink("Statistics!A1", "Statistics");
hyperLink.SetPosition(13, 0, 9, 0);
hyperLink.SetSize(70, 30);
hyperLink.EditAs = eEditAs.Absolute;
hyperLink.Border.Fill.Style = eFillStyle.NoFill;
hyperLink.Fill.Style = eFillStyle.NoFill;
hyperLink.Text = "Statistics";
hyperLink.Font.UnderLine = eUnderLineType.Single;
hyperLink.Font.Fill.Color = Color.Blue;
```

```vbnet
'Add a drawing with a HyperLink to the statistics sheet.
'We add the hyperlink as a drawing here, as we don't want it to move when we expand and collapse rows.
Dim hyperLink = ws.Drawings.AddShape("HyperLink", eShapeStyle.Rect)
hyperLink.Hyperlink = New ExcelHyperLink("Statistics!A1", "Statistics")
hyperLink.SetPosition(13, 0, 9, 0)
hyperLink.SetSize(70, 30)
hyperLink.EditAs = eEditAs.Absolute
hyperLink.Border.Fill.Style = eFillStyle.NoFill
hyperLink.Fill.Style = eFillStyle.NoFill
hyperLink.Text = "Statistics"
hyperLink.Font.UnderLine = eUnderLineType.Single
hyperLink.Font.Fill.Color = Color.Blue
```

## See also

More extensive examples are available in our sample projects:  
[Sample 1.6](<https://github.com/EPPlusSoftware/EPPlus.Samples.CSharp/tree/master/01-Workbook worksheet and ranges/06-Sales report with hyperlinks>) and [Sample 3.4](<https://github.com/EPPlusSoftware/EPPlus.Samples.CSharp/blob/master/03-Styling/04-Create a file system report>) for **C\#**  
[Sample 1.6](<https://github.com/EPPlusSoftware/EPPlus.Samples.VB/tree/master/01-Workbook worksheet and ranges/06-Sales report with hyperlinks>) and [Sample 3.4-VB](<https://github.com/EPPlusSoftware/EPPlus.Samples.VB/blob/master/03-Styling/04-Create a file system report>) for **Visual Basic**
