Ajouter des hyperliens d image
Contents
[
Hide
]
Les hyperliens sont utiles pour accéder à des informations sur d’autres feuilles de calcul ou des sites Web. Microsoft Excel permet aux utilisateurs d’ajouter des liens hypertexte sur du texte dans des cellules et sur des images. Les hyperliens d’image peuvent faciliter la navigation dans une feuille de calcul, par exemple, en tant que boutons suivants et précédents ou logos qui renvoient à des sites spécifiques. Ce document explique comment insérer des hyperliens d’image dans une feuille de calcul en utilisant Aspose.Cells pour Python via .NET.
Aspose.Cells pour Python via .NET permet d’ajouter des hyperliens vers des images dans les feuilles de calcul en cours d’exécution. Il est possible de définir et de modifier l’infobulle et l’adresse du lien. Le code d’exemple suivant illustre comment ajouter un hyperlien d’image dans une feuille de calcul.
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
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) |