检测超链接类型

检测超链接类型

Excel文件可以具有不同类型的超链接,例如外部链接,单元格引用,文件路径等。Aspose.Cells for Python via .NET支持检测超链接的功能。超链接的类型由TargetModeType枚举表示。TargetModeType枚举具有以下成员。

  • EXTERNAL: 外部链接
  • FILE_PATH: 本地和完整的文件\文件夹路径。
  • EMAIL: 电子邮件
  • CELL_REFERENCE:链接到单元格或已命名范围。

要检查超链接的类型,Hyperlink 类提供了一个返回类型为 TargetModeTypelink_type 属性。以下代码片段演示了如何使用 link_type 属性,通过使用此source excel file

源代码

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))

以下是上述代码片段生成的输出。

控制台输出

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>