Articles in this section

How to add hyperlink to an Excel cell using C#, VB.NET?

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files.

This article explains how to add a hyperlink to an Excel cell that redirects to another worksheet using C# and VB.NET.

Include the following namespace in the Program.cs file.

C#

using Syncfusion.XlsIO;

VB.NET

Imports Syncfusion.XlsIO

Use the following code snippet for adding a hyperlink to an Excel cell that redirects to another worksheet.

C#

using (ExcelEngine excelEngine = new ExcelEngine())
{
    IApplication application = excelEngine.Excel;
    application.DefaultVersion = ExcelVersion.Xlsx;
    FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.xlsx"), FileMode.Open, FileAccess.Read);
    IWorkbook workbook = application.Workbooks.Open(inputStream);
    IWorksheet sheet1 = workbook.Worksheets[0];
    IWorksheet sheet2 = workbook.Worksheets[1];

    //Add a hyperlink to cell A1 in Sheet1
    IHyperLink hyperlink = sheet1.HyperLinks.Add(sheet1["A1"]);

    //Set the hyperlink type to Workbook
    hyperlink.Type = ExcelHyperLinkType.Workbook;

    //Specify the target cell address in Sheet2
    hyperlink.Address = "Sheet2!A1";

    //Set the screen tip that appears when hovering over the hyperlink
    hyperlink.ScreenTip = "Click here";

    //Set the display text for the hyperlink in the cell
    hyperlink.TextToDisplay = "Go to Sheet2, Cell A1";

    //Saving the workbook
    FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.xlsx"), FileMode.Create, FileAccess.Write);
    workbook.SaveAs(outputStream);

    //Dispose streams
    outputStream.Dispose();
    inputStream.Dispose();
}

VB.NET

Using excelEngine As New ExcelEngine()
    Dim application As IApplication = excelEngine.Excel
    application.DefaultVersion = ExcelVersion.Xlsx
    Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx")
    Dim sheet1 As IWorksheet = workbook.Worksheets(0)
    Dim sheet2 As IWorksheet = workbook.Worksheets(1)

    'Add a hyperlink to cell A1 in Sheet1
    Dim hyperlink As IHyperLink = sheet1.HyperLinks.Add(sheet1("A1"))

    'Set the hyperlink type to Workbook
    hyperlink.Type = ExcelHyperLinkType.Workbook

    'Specify the target cell address in Sheet2
    hyperlink.Address = "Sheet2!A1"

    'Set the screen tip that appears when hovering over the hyperlink
    hyperlink.ScreenTip = "Click here"

    'Set the display text for the hyperlink in the cell
    hyperlink.TextToDisplay = "Go to Sheet2, Cell A1"

    'Saving the workbook
    workbook.SaveAs("Output.xlsx")
End Using

You can get the complete sample for adding a hyperlink to an Excel cell that redirects to another worksheet from

Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and, protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.

Conclusion

I hope you enjoyed learning about how to add hyperlink to an Excel cell using C#, VB.NET.

You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our documentation and online demos to understand how to manipulate data in Excel documents.

If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion components.

If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied