检测超链接类型
Contents
[
Hide
]
检测超链接类型
Excel文件可以有不同类型的超链接,例如外部链接、单元格引用、文件路径等。Aspose.Cells支持检测超链接类型的功能。超链接的类型由TargetModeType枚举表示。TargetModeType枚举具有以下成员。
- 外部:外部链接
- 文件路径:文件/文件夹的本地和完整路径。
- 电子邮件:邮件
- 单元格引用:链接到单元格或命名范围。
要检查超链接的类型,Hyperlink 类提供了一个返回类型为 TargetModeType 的 LinkType 属性。以下代码片段演示了如何使用 LinkType 属性,通过使用此source excel file。
源代码
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); | |
} |
以下是上述代码片段生成的输出。
控制台输出
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>