画像ハイパーリンクの追加
Contents
[
Hide
]
ハイパーリンクは、他のワークシートやウェブサイトの情報にアクセスするために便利です。Microsoft Excel では、セル内のテキストや画像にハイパーリンクを追加することができます。画像ハイパーリンクは、ワークシートのナビゲーションを簡単にするための次へ、前へボタン、特定のサイトにリンクするロゴなどとして使用できます。このドキュメントでは、Aspose.Cells を使用してワークシートに画像ハイパーリンクを挿入する方法について説明します。
Aspose.Cells では、ランタイムでスプレッドシート内の画像にハイパーリンクを追加することが可能です。リンクの画面上のヒントやアドレスを設定および変更することができます。
次のサンプルコードは、ワークシートに画像ハイパーリンクを追加する方法を示しています。
コードを実行すると、画像ハイパーリンクが含まれた出力ファイルが保存されます。
出力ファイル
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-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"); |