Manage Hyperlinks

Spread.Services Documentation
Manage Hyperlinks
Collapse All Expand All

Spread.Services Documentation > Developer's Guide > Customize User Interaction > Manage Hyperlinks

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.

- Add Hyperlinks
- Configure Hyperlinks
- Delete Hyperlinks

### Add 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");

### Configure Hyperlinks

Hyperlinks can be configured using the following properties of the IHyperlink interface.

1. You can use the Address and SubAddress properties of the IHyperlink interface to configure the hyperlink references. The table shown below illustrates both of these properties with examples:

   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

2. You can use the EmailSubject property to set the text of hyperlink's email subject line.
3. You can use the ScreenTip property to set the tip text for the specified hyperlink.
4. You can use the TextToDisplay property to set the text to be displayed for the specified hyperlink.

### Delete Hyperlinks

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();

Copyright © GrapeCity, inc. All rights reserved.