Detect Hyperlink Type
Contents
[
Hide
]
Detect Hyperlink Type
An Excel file can have different types of hyperlinks like external, cell reference, file path, etc. Aspose.Cells 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
- FilePath: Local and full path to files\folders.
- Email: Email
- CellReference: Link to cell or named range.
To check the type of hyperlink, the Hyperlink class provides a LinkType property with a return type of TargetModeType. The following code snippet demonstrates the use of the LinkType property by using this source excel file.
Source Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//source directory | |
string SourceDir = RunExamples.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(SourceDir + "LinkTypes.xlsx"); | |
// Get the first (default) worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range A2:B3 | |
Range range = worksheet.Cells.CreateRange("A1", "A7"); | |
// Get Hyperlinks in range | |
Hyperlink[] hyperlinks = range.Hyperlinks; | |
foreach (Hyperlink link in hyperlinks) | |
{ | |
Console.WriteLine(link.TextToDisplay + ": " + link.LinkType); | |
} |
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>