In Spread.Services, hyperlinks can be created and inserted in cells to allow users to quickly access related information present in another file or on a webpage by clicking on the link.
Hyperlinks are stored in a specific worksheet or in a range by accessing the Hyperlinks collection of the IWorksheet interface and the IRange interface respectively.
In Spread.Services, you can perform the following tasks to manage hyperlinks.
Hyperlinks can be created and inserted through linking to an external file, linking to a webpage, linking to an email address and also linking to a range within the worksheet. You can add hyperlinks for a range of cells in a worksheet using the Add method of the IHyperLinks interface.
Refer to the following example code to insert hyperlinks to an external file, to a webpage, to a range within the worksheet and to an email address.
C# |
Copy Code |
---|---|
// Add a hyperlink link to external file worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"], @"C:\Documents\Spread.Core(TFS)\Spread.Core\SpreadCoreProject\Hyperlink\SampleFile.xlsx", null, "link to SampleFile.xlsx file.", "SampleFile.xlsx"); |
C# |
Copy Code |
---|---|
// Add a hyperlink link to web page worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"], "http://www.grapecity.com/", null, "open Grapecity web site.", "Grapecity"); |
C# |
Copy Code |
---|---|
//Add a hyperlink link to a range in this document. worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"], null, "Sheet1!$C$3:$E$4", "Go To sheet1 C3:E4"); |
C# |
Copy Code |
---|---|
//Add a hyperlink link to email address. worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"], "mailto:abc.xyz@grapecity.com", null, "Send an email to ABC", "Send To ABC"); |
Hyperlinks can be configured using the following properties of the IHyperlink interface.
Link To | Address | SubAddress |
---|---|---|
External File | Example: "C:\Users\sophiacao.GRAPECITY\Desktop\test.xlsx" | null |
Webpage | Example: "http://www.baidu.com/" | null |
A range in this document | Example: null | "Sheet1!$C$3:$E$4" |
Email Address | Example: "mailto:abc.cao@grapecity.com" | null |
The hyperlinks inserted in the cells can be removed from the hyperlinks collection in a specific worksheet or in a specific range using the Delete method.
Refer to the following example code to delete hyperlinks.
C# |
Copy Code |
---|---|
//Delete hyperlinks. worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1:A2"], null, "Sheet1!$C$3:$E$4", "Go To sheet1 C3:E4"); worksheet.Range["H5"].Hyperlinks.Add(worksheet.Range["A1"], "http://www.grapecity.com/"); worksheet.Range["J6"].Hyperlinks.Add(worksheet.Range["A1"], "http://www.grapecity.com/"); //delete hyperlinks in range A1:A2. worksheet.Range["A1:A2"].Hyperlinks.Delete(); //delete all hyperlinks in this worksheet. worksheet.Hyperlinks.Delete(); |