添加图像超链接
Contents
[
Hide
]
超链接对于访问其他工作表或网站上的信息非常有用。Microsoft Excel允许用户在单元格中的文本和图像上添加超链接。图像超链接可以使工作表的导航更加简单,例如下一个和上一个按钮,或者链接到特定网站的标志。本文档解释了如何使用Aspose.Cells for Python via .NET在工作表中插入图像超链接。
Aspose.Cells for Python via .NET允许您在运行时向电子表格中的图像添加超链接。可以设置和修改链接的屏幕提示和地址。以下示例代码说明了如何将图像超链接添加到工作表中。
This file contains hidden or 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
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new workbook | |
workbook = Workbook() | |
# Get the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Insert a string value to a cell | |
worksheet.cells.get("C2").put_value("Image Hyperlink") | |
# Set the 4th row height | |
worksheet.cells.set_row_height(3, 100) | |
# Set the C column width | |
worksheet.cells.set_column_width(2, 21) | |
# Add a picture to the C4 cell | |
index = worksheet.pictures.add(3, 2, 4, 3, dataDir + "aspose-logo.jpg") | |
# Get the picture object | |
pic = worksheet.pictures[index] | |
# Set the placement type | |
pic.placement = PlacementType.FREE_FLOATING | |
# Add an image hyperlink | |
hlink = pic.add_hyperlink("http://www.aspose.com/") | |
# Specify the screen tip | |
hlink.screen_tip = "Click to go to Aspose site" | |
dataDir = dataDir + "ImageHyperlink.out.xls" | |
# Save the Excel file | |
workbook.save(dataDir) |