Manage Hyperlinks in Worksheet

Generally,the following hyperlinks are supported by Aspose.Cells.GridWeb:

The below sections describe the use of all types of hyperlinks in detail. It also discusses how to access or remove links.

URL hyperlinks look more like simple hyperlinks that you normally see on websites. A URL hyperlink works like an anchor in a cell. Whenever it is clicked, it navigates to a web page or opens a new browser window.

There are different types of URL hyperlinks:

  • Text hyperlinks.
  • Image hyperlinks.

Developers can specify an image for the hyperlink. If an image isn’t specified, a text hyperlink is created; else an image hyperlink is created.

To add a text hyperlink to a worksheet:

  1. Add the Aspose.Cells.GridWeb control to your Web Form.
  2. Access a worksheet.
  3. Add a hyperlink to a cell in the worksheet.
  4. Set the text that will be shown in the cell.
  5. Set the hyperlink’s URL.
  6. Set the hyperlink’s target,if desired.
  7. Set a tool tip, if desired.

The example below adds two hyperlinks to a worksheet. One has no target while the other is set to _parent.

Output: text hyperlinks added to worksheet

todo:image_alt_text

To add an image hyperlink:

  1. Add the Aspose.Cells.GridWeb control to your Web Form.
  2. Access a worksheet.
  3. Add a hyperlink to a cell.
  4. Set the URL of the image that will be displayed as hyperlink.
  5. Set the hyperlink URL.
  6. Set a tool tip, if desired.
  7. Set the hyperlink text, if desired.

Output: image hyperlinks added to worksheet

todo:image_alt_text

A cell command hyperlink is a special type of hyperlink which triggers a server-side event instead of opening a web page. Developers can add code to the server-side event and perform any task when the hyperlink is clicked. This feature enables developers to create more interactive applications.

To add a cell command hyperlink:

  1. Add the Aspose.Cells.GridWeb control to your Web Form.
  2. Access a worksheet.
  3. Add a hyperlink to a cell.
  4. Set the hyperlink’s Command to any desired value. The value is used by the hyperlink’s event handler to recognise it.
  5. Set a tool tip, if desired.
  6. Set the URL for the Image that will be displayed as a hyperlink.

A cell command hyperlink has been added to worksheet

todo:image_alt_text

Developers need to create an event handler for the GridWeb control’s CellCommand event to perform specific tasks when a specific cell command hyperlink is clicked. The CellCommand event’s event handler provides an object of the CellEventArgs type that offers the Argument property. Use the Argument property to identify a specific hyperlink by comparing its CellCommand value.

The example below creates an event handler for the cell command hyperlink created in the code above. The hyperlink’s CellCommand was set to Click. So, in the event handler, first check it and then add code which displays a message in the A6 cell.

The event handler is invoked when the hyperlink is clicked.

Output: text added to A6 cell when hyperlink is clicked

todo:image_alt_text

To access an existing hyperlink:

  1. Access the cell that contains it.
  2. Get the cell reference.
  3. Pass the reference to the Hyperlinks collection’s GetHyperlink method to access the hyperlink.
  4. Modify the hyperlink’s properties.

To remove a hyperlink:

  1. Access the active worksheet.
  2. Remove a hyperlink using the Hyperlinks collection’s Remove method.