Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
A hyperlink is used to create a link between two entities. Everybody is familiar with the use of hyperlinks, especially on websites.
Using Aspose.Cells, developers can create different kinds of hyperlinks in Microsoft Excel files. This topic discusses what types of hyperlinks are supported by Aspose.Cells and how they can be used in our Excel files.
Three types of hyperlink can be added to a cell using Aspose.Cells:
Aspose.Cells allows developers to add hyperlinks to Excel files either using the API or designer spreadsheets (spreadsheets where hyperlinks are created manually and Aspose.Cells is used to import them into other spreadsheets).
Aspose.Cells provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a WorksheetCollection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides different methods for adding different hyperlinks to Excel files.
The Worksheet class contains a Hyperlinks collection. Each item in the Hyperlinks collection represents a Hyperlink. Add hyperlinks to URLs by calling the Hyperlinks collection’s Add method. The Add method takes the following parameters:
C#
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
//Adding a hyperlink to a URL at "A1" cell
worksheet.Hyperlinks.Add("A1", 1, 1, "http://www.aspose.com");
//Saving the Excel file
workbook.Save("C:\\book1.xls");
It is possible to add hyperlinks to cells in the same Excel file by calling the Hyperlink collection’s Add method. The Add method works for both internal and external hyperlinks. One version of the overloaded method takes the following parameters:
C#
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first (default) worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in
//the same Excel file
worksheet.Hyperlinks.Add("B3", 1, 1, "Sheet2!B9");
//Saving the Excel file
workbook.Save("C:\\book1.xls");
It is possible to add hyperlinks to external Excel files by calling the Hyperlinks collection’s Add method. The Add method takes the following parameters:
C#
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int i = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
//Adding an internal hyperlink to the "B9" cell of the other worksheet "Sheet2" in
//the same Excel file
worksheet.Hyperlinks.Add("A5", 1, 1, "C:\\book1.xls");
//Saving the Excel file
workbook.Save("C:\\book2.xls");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.