Detect Hyperlink Type

An Excel file can have different types of hyperlinks like external, cell reference, file path, etc. Aspose.Cells for Python via .NET supports the feature to detect the type of hyperlink. The types of hyperlinks are represented by the TargetModeType Enumeration. The TargetModeType Enumeration has the following members.

  • EXTERNAL: External link
  • FILE_PATH: Local and full path to files\folders.
  • EMAIL: Email
  • CELL_REFERENCE: Link to cell or named range.

To check the type of hyperlink, the Hyperlink class provides a link_type property with a return type of TargetModeType. The following code snippet demonstrates the use of the link_type property by using this source excel file.

Source Code

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# source directory
SourceDir = RunExamples.Get_SourceDirectory()
workbook = Workbook(SourceDir + "LinkTypes.xlsx")
# Get the first (default) worksheet
worksheet = workbook.worksheets[0]
# Create a range A2:B3
range = worksheet.cells.create_range("A1", "A7")
# Get Hyperlinks in range
hyperlinks = range.hyperlinks
for link in hyperlinks:
print(link.text_to_display + ": " + str(link.link_type))

The following is the output generated by the code snippet given above.

Console Output

LinkTypes.xlsx: FilePath </br>
C:\Windows\System32\cmd.exe: FilePath </br>
C:\Program Files\Common Files: FilePath </br>
'Test Sheet'!B2: CellReference </br>
FullPathExample: CellReference </br>
https://products.aspose.com/cells/ : External </br>
mailto:test@test.com?subject=TestLink: Email </br>