[]
        
(Showing Draft Content)

Hyperlinks

GcExcel .NET allows users to create references to the data in the form of hypertext links that point towards another document or a section within the same document. A worksheet or a range can have multiple hyperlinks. 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.

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.

// Add a hyperlink link to external file
worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"],
                                @"C:\Documents\GcExcel\GrapeCityDocumentsExcel\Project\Hyperlink\SampleFile.xlsx",
                                null,
                                "link to SampleFile.xlsx file.",
                                "SampleFile.xlsx");
// Add a hyperlink link to web page
worksheet.Range["A1:B2"].Hyperlinks.Add(worksheet.Range["A1"],
                                   "http://www.grapecity.com.cn/",
                                   null,
                                   "open Grapecity web site.",
                                   "Grapecity");
 //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");
//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.

  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\Desktop\test.xlsx"

    null

    Webpage

    Example:  "http://www.grapecity.com.cn/"

    null

    A range in this document

    Example: null

    "Sheet1!$C$3:$E$4"

    Email Address

    Example: "mailto: abc.xyz@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.

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.

//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.cn/");
worksheet.Range["J6"].Hyperlinks.Add(worksheet.Range["A1"], "http://www.grapecity.com.cn/");

//delete hyperlinks in range A1:A2.
worksheet.Range["A1:A2"].Hyperlinks.Delete();

//delete all hyperlinks in this worksheet.
worksheet.Hyperlinks.Delete();