# Hyperlink on Shape

DsExcel allows you to add hyperlinks to various shapes types like connectors, charts, etc. Learn how to add and delete a hyperlink on a shape in a worksheet.

## Content

In DsExcel, hyperlinks can be added to various shape types like basic shapes, charts, connectors, pictures and group shapes. It allows users to quickly navigate to related information on a webpage, external file, specific range in the same workbook, or email address by clicking on the shape.

>type=note
> **Note**: Hyperlink cannot be added to **Comment** and **Slicer** shape types.

Hyperlinks can be configured using the following properties of the [IHyperlink](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html) interface.

1. The [setAddress](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html#setAddress) and [setSubAddress](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html#setSubAddress) methods of the IHyperlink interface can be used to configure the hyperlink references. The table shown below illustrates both the properties with examples:

    | **Link To** | **Address** | **SubAddress** |
    | ------- | ------- | ---------- |
    | External File | Example: "C:\\Users\\Desktop\\test.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: abc.xyz@mescius.com" | null |
2. The [setEmailSubject](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html#setEmailSubject) method can be used to set the text of hyperlink's email subject line.
3. The [setScreenTip](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html#setScreenTip) method can be used to set the tip text for the specified hyperlink.
4. The [setTextToDisplay](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlink.html#setTextToDisplay) method can be used to set the text to be displayed for the specified hyperlink.

## Add Hyperlink

A user can add hyperlink to a shape in a worksheet using the [Add](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlinks.html#add) method of the [IHyperLinks](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlinks.html) interface.
Refer to the following example code to insert hyperlinks on shapes to redirect to an external file, webpage, range within the worksheet and email address.

```Java
// Add a hyperlink to external file
        
// Initialize workbook
Workbook workbook = new Workbook();
// Fetch default worksheet
IWorksheet worksheet = workbook.getWorksheets().get(0);
// Add a Shape
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 1, 1, 200, 100);
shape.getTextFrame().getTextRange().getParagraphs().add("Link to Test.xlsx file");
// Add Hyperlink
worksheet.getHyperlinks().add(shape, "C:\\Test.xlsx", null, "Link to Test.xlsx file", "Test.xlsx");

// Save to an excel file
workbook.save("402-LinkExternalFile.xlsx", SaveFileFormat.Xlsx);
```

```Java
// Add a hyperlink to web page
        
// Add a Shape
IShape picture = null;
try {
    picture = worksheet.getShapes().addPicture("logo.jpg", 1, 1, 100, 100);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
// Add Hyperlink
worksheet.getHyperlinks().add(picture, "https://developer.mescius.com/", null, "Click to Open", "MESCIUS, Inc.");
// Save to an excel file
workbook.save("401-ShapeHyperlink.xlsx", SaveFileFormat.Xlsx);
```

```Java
// Add a Shape
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 1, 1, 200, 100);
shape.getTextFrame().getTextRange().getParagraphs().add("Go To sheet1 J3:K4");
// Add Hyperlink
worksheet.getHyperlinks().add(shape, null, "Sheet1!J3:K4", "Go To Sheet1 D3:E4", null);

// Save to an excel file
workbook.save("403-HyperlinkRange.xlsx", SaveFileFormat.Xlsx);
```

```Java
//Add a hyperlink to email address.
        
// Add a Shape
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 1, 1, 200, 100);
shape.getTextFrame().getTextRange().getParagraphs().add("Send Feedback");
// Add Hyperlink
worksheet.getHyperlinks().add(shape, "mailto:web_feedback@mescius.com", null, "Send your valuable feedback.",
        "Feedback");

// Save to an excel file
workbook.save("404-HyperlinkMailTo.xlsx", SaveFileFormat.Xlsx);
```

## Delete Hyperlink

The hyperlink on the shape can be removed using the [Delete](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IHyperlinks.html#delete) method of the **IHyperlink** interface.
Refer to the following example code to delete hyperlink.

```Java
//Delete a hyperlink.
        
// Add a Shape
IShape shape = worksheet.getShapes().addShape(AutoShapeType.Oval, 1, 1, 200, 100);

// Create Hyperlinks
IHyperlink hyperlink1 = worksheet.getHyperlinks().add(shape, "https://developer.mescius.com/", null, "Click to Open",
        "MESCIUS, Inc.");

// Delete hyperlink1.
hyperlink1.delete();

// Save to an excel file
workbook.save("405-DeleteHyperlink.xlsx", SaveFileFormat.Xlsx);
```