Skip to content

Hyperlinks

Mats Alm edited this page Nov 10, 2026 · 13 revisions

This page has moved. The current version of this page is at https://epplussoftware.com/docs/worksheet-and-ranges/cell-content/hyperlinks/. The EPPlus documentation is no longer updated in this wiki; please use the EPPlus guides and update your bookmarks.

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:

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;

To style the hyperlinks you can create a named style for Hyperlinks:

var namedStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink");
namedStyle.BuildInId = 8; // This is the id for the built-in hyperlink style.

var namedStyle = package.Workbook.Styles.CreateNamedStyle("Followed HyperLink");
namedStyle.BuildInId = 9; // This is the id for the built-in followed hyperlink style.

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

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:

// 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;

See also

More extensive examples are available in our sample projects: Sample 1.6 and Sample 3.4 for C#
Sample 1.6 and Sample 3.4-VB for Visual Basic

EPPlus wiki

Versions

Worksheet & Ranges

Styling

Import/Export data

Formulas and filters

Charts & Drawing objects

Tables & Pivot Tables

VBA & Protection

Clone this wiki locally

⌂ 换网址