添加图像超链接
Contents
[
Hide
]
超链接对于访问其他工作表或网站上的信息很有用。 Microsoft Excel 允许用户向单元格和图像中的文本添加超链接。图像超链接可以使工作表的导航更容易,例如,作为下一个和上一个按钮,或链接到特定站点的徽标。本文档说明如何使用 Aspose.Cells 在工作表中插入图像超链接。
Aspose.Cells 允许您在运行时向电子表格中的图像添加超链接。可以设置和修改链接的屏幕提示和地址。
以下示例代码说明了如何将图像超链接添加到工作表中。
当代码运行时,它会保存一个带有图像超链接的输出文件。
输出文件
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getDataDir(AddImageHyperlinks.class); | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Insert a string value to a cell | |
worksheet.getCells().get("C2").setValue("Image Hyperlink"); | |
// Set the 4th row height | |
worksheet.getCells().setRowHeight(3, 100); | |
// Set the C column width | |
worksheet.getCells().setColumnWidth(2, 21); | |
// Add a picture to the C4 cell | |
int index = worksheet.getPictures().add(3, 2, 4, 3, dataDir + "aspose-logo.jpg"); | |
// Get the picture object | |
com.aspose.cells.Picture pic = worksheet.getPictures().get(index); | |
// Set the placement type | |
pic.setPlacement(PlacementType.FREE_FLOATING); | |
// Add an image hyperlink | |
pic.addHyperlink("http://www.aspose.com/"); | |
com.aspose.cells.Hyperlink hlink = pic.getHyperlink(); | |
// Specify the screen tip | |
hlink.setScreenTip("Click to go to Aspose site"); | |
// Save the Excel file | |
workbook.save(dataDir + "ImageHyperlink.xls"); |