Document Solutions for Excel, Java Edition | Document Solutions
Features / Hyperlinks
In This Topic
    Hyperlinks
    In This Topic

    With DsExcel Java, you can insert and manage hyperlinks in the cells of the worksheets without any hassle.

    Basically, a hyperlink in a cell refers to the hypertext link that is entered into a cell in order to assign data reference that point to another externally located file or a section within the document. Users can insert multiple hyperlinks in a worksheet or a cell range depending on the requirements.

    In DsExcel Java, you can work with hyperlinks in the following ways:

    Add hyperlinks

    Hyperlinks can be added via linking to an external file, linking to a webpage, linking to an email address and linking to a cell or a range of cells within the worksheet. You can insert hyperlinks using the add method of the IHyperlinks interface.

    In order to add hyperlinks to an external file, to a webpage, to a range within the worksheet and to an email address; refer to the following example code.

    Java
    Copy Code
    // Add hyperlink to an external file
    worksheet.getRange("A1:B2").getHyperlinks().add(worksheet.getRange("A1"), 
        "C:\Documents\Project\Hyperlink\SampleFile.xlsx", 
        null, 
        "link to SampleFile.xlsx file.", 
        "SampleFile.xlsx");
    Java
    Copy Code
    // Add hyperlink to a webpage
    worksheet.getRange("A1:B2").getHyperlinks().add(worksheet.getRange("A1"),
        "https://developer.mescius.com/", null, "open Mescius website.","MESCIUS, Inc.");
    Java
    Copy Code
    // Add hyperlink to a range in this document
    worksheet.getRange("A1:B2").getHyperlinks().add(worksheet.getRange("A1"), 
        null, "Sheet1!$C$3:$E$4", "Go To sheet1 C3:E4","");
    Java
    Copy Code
    // Add hyperlink to a range in this document
    worksheet.getRange("A1:B2").getHyperlinks().add(worksheet.getRange("A1"), 
            "mailto:us.sales@mescius.com", 
            null, 
            "Send an email to sales department", 
            "Send To US Sales");

    Configure Hyperlinks

    You can configure hyperlinks using the methods of the IHyperlink interface.

    1. The methods of the IHyperlink interface enables users to configure the hyperlink references. The table shared below illustrates some examples:
      Link To Address SubAddress
      External File Example: "C:\Documents\Project\Hyperlink\SampleFile.xlsx" null
      Webpage Example:  "https://developer.mescius.com/" null
      A range in this document Example: null "Sheet1!$C$3:$E$4"
      Email Address Example: mailto:us.sales@mescius.com null

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

    Delete Hyperlinks

    The hyperlinks added in the cells can be deleted from the worksheet or in a specific cell range using the delete method.

    In order to remove hyperlinks, refer to the following example code.

    Java
    Copy Code
    // Delete hyperlinks
    worksheet.getRange("A1:B2").getHyperlinks().add(worksheet.getRange("A1:A2"), null, "Sheet1!$C$3:$E$4", "Go To sheet1 C3:E4", "");
    worksheet.getRange("H5").getHyperlinks().add(worksheet.getRange("A1"), "https://developer.mescius.com");
    worksheet.getRange("J6").getHyperlinks().add(worksheet.getRange("A1"), "https://developer.mescius.com");
    
    // Delete hyperlinks in range A1:A2
    worksheet.getRange("A1:A2").getHyperlinks().delete();
    
    // Delete all hyperlinks in this worksheet
    worksheet.getHyperlinks().delete();