Excel Hyperlink guides users to get more information about data in one cell. For example, the hyperlink links text (city name) in cell to a city history webpage and can help readers learn more about a city. Besides website address, the hyperlink can be an Email address or a file. Generally speaking, if data in on cell is website address like www.e-iceblue.com or Email address, the hyperlink will be generated automatically.
Spire.XLS for .NET, a professional .NET Excel component to generate, open and write Excel files, enables users to insert hyperlink in Excel by using C#, VB.NET. This guide illustrates how to realize this function quickly via Spire.XLS for .NET.
Now, I will insert hyperlink for Text “Chicago” and the Email address besides “Chicago” cell. Invoke sheet.Hyperlinks.Add(cellRange) method to insert hyperlink for specified cell. Then, set TextToDisplay, Type, Address properties for this hyperlink.Download and install Spire.XLS for .NET. Use the following code to insert hyperlink in Excel with C#, VB.NET.
using Spire.Xls; namespace ExcelHyperlink { class XLSLink { static void Main(string[] args) { Workbook workbook = new Workbook(); workbook.LoadFromFile(@"E:\Work\Documents\ExcelFiles\Student Info.xlsx"); Worksheet sheet = workbook.Worksheets[0]; HyperLink UrlLink= sheet.HyperLinks.Add(sheet.Range["E8"]); UrlLink.TextToDisplay = sheet.Range["E8"].Text; UrlLink.Type=HyperLinkType.Url; UrlLink.Address="http://en.wikipedia.org/wiki/Chicago"; HyperLink MailLink = sheet.HyperLinks.Add(sheet.Range["F8"]); MailLink.TextToDisplay = sheet.Range["F8"].Text; MailLink.Type = HyperLinkType.Url; MailLink.Address = "mailto:ka.Lee220@hotmail.com"; workbook.SaveToFile("ExcelHyperlink.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("ExcelHyperlink.xlsx"); } } }
Imports Spire.Xls Namespace ExcelHyperlink Friend Class XLSLink Shared Sub Main(ByVal args() As String) Dim workbook As New Workbook() workbook.LoadFromFile("E:\Work\Documents\ExcelFiles\Student Info.xlsx") Dim sheet As Worksheet = workbook.Worksheets(0) Dim UrlLink As HyperLink = sheet.HyperLinks.Add(sheet.Range("E8")) UrlLink.TextToDisplay = sheet.Range("E8").Text UrlLink.Type = HyperLinkType.Url UrlLink.Address = "http://en.wikipedia.org/wiki/Chicago" Dim MailLink As HyperLink = sheet.HyperLinks.Add(sheet.Range("F8")) MailLink.TextToDisplay = sheet.Range("F8").Text MailLink.Type = HyperLinkType.Url MailLink.Address = "mailto:ka.Lee220@hotmail.com" workbook.SaveToFile("ExcelHyperlink.xlsx", ExcelVersion.Version2010) System.Diagnostics.Process.Start("ExcelHyperlink.xlsx") End Sub End Class End Namespace