ワークシートでのハイパーリンクの管理
Contents
[
Hide
]
Aspose.Cells.GridDesktop を使用すると、ワークシートのセルに格納されている単純な値にハイパーリンクを追加することもできます。一部のセルに、Web ページのより詳細な情報にリンクしたい値があるとします。その場合、そのセルにハイパーリンクを追加して、ユーザーがセルをクリックするとその Web ページに移動するようにすることが望ましいでしょう。このトピックでは、開発者がワークシートにハイパーリンクを追加および操作する方法について説明します。
ハイパーリンクの追加
Aspose.Cells.GridDesktop を使用してセルにハイパーリンクを追加するには、次の手順に従ってください。
- Aspose.Cells.GridDesktop コントロールを形
- 任意のアクセスワークシート
- 希望のアクセスCellハイパーリンクされるワークシートで
- ハイパーリンクするセルに値を追加します
- 追加ハイパーリンクハイパーリンクが適用されるセル名を指定して、ワークシートに
ハイパーリンクのコレクションワークシートオブジェクトはオーバーロードを提供します追加方法。開発者は、オーバーロードされた任意のバージョンを使用できます追加特定のニーズに応じた方法。
以下のコードはハイパーリンクを追加しますB2とC3ワークシートのセル。
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-.NET | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
// Accessing cell of the worksheet | |
GridCell cell = sheet.Cells["b2"]; | |
GridCell cell2 = sheet.Cells["c3"]; | |
// Modifying the width of the column of the cell | |
sheet.Columns[cell.Column].Width = 160; | |
sheet.Columns[cell2.Column].Width = 160; | |
// Adding a value to the cell | |
cell.Value = "Aspose Home"; | |
cell2.Value = "Aspose Home"; | |
// Adding a hyperlink to the worksheet containing cell name and the hyperlink URL with which the cell will be linked | |
sheet.Hyperlinks.Add("b2", "www.aspose.com"); | |
sheet.Hyperlinks.Add("c3", "www.aspose.com"); |
ハイパーリンクへのアクセス
ハイパーリンクがセルに追加されると、実行時にハイパーリンクにアクセスして変更する必要がある場合もあります。これを行うには、開発者はハイパーリンクに簡単にアクセスできます。ハイパーリンクのコレクションワークシートハイパーリンクを追加するセルを (セル名またはセルの行番号と列番号を使用して) 指定します。ハイパーリンクにアクセスすると、開発者は実行時にその URL を変更できます。
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-.NET | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
// Accessing a hyperlink added to "c3,b2" cells (specified using its row & column number) | |
Aspose.Cells.GridDesktop.Data.GridHyperlink hyperlink1 = sheet.Hyperlinks[2, 2]; | |
Aspose.Cells.GridDesktop.Data.GridHyperlink hyperlink2 = sheet.Hyperlinks[1, 1]; | |
if (hyperlink1 != null && hyperlink2 != null) | |
{ | |
// Modifying the Url of the hyperlink | |
hyperlink1.Url = "www.aspose.com"; | |
hyperlink2.Url = "www.aspose.com"; | |
MessageBox.Show("Hyperlinks are accessed and URL's are: \n" + hyperlink1.Url + "\n" + hyperlink2.Url); | |
} | |
else | |
{ | |
MessageBox.Show("No hyperlinks are found in sheet. Add hyperlinks first."); | |
} |
ハイパーリンクの削除
既存のハイパーリンクを削除するには、開発者は単に目的のワークシートにアクセスしてから削除するからのハイパーリンクハイパーリンクのコレクションワークシートハイパーリンクされたセルを指定する (その名前または行と列の番号を使用)。
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-.NET | |
// Accessing first worksheet of the Grid | |
Worksheet sheet = gridDesktop1.Worksheets[0]; | |
if (sheet.Hyperlinks.Count > 0) | |
{ | |
// Removing hyperlink from "c3" cell | |
sheet.Hyperlinks.Remove(2, 2); | |
MessageBox.Show("Hyperlink in C3 cell has been removed."); | |
} | |
else | |
{ | |
MessageBox.Show("No hyperlinks are found in sheet to remove. Add hyperlinks first."); | |
} |
セルにハイパーリンクを追加し、値の代わりにハイパーリンクの URL をセルに表示したい場合は、セルに値を追加せず、ハイパーリンクをそのセルに追加するだけです。そうすることで、セルはハイパーリンクされ、ハイパーリンクの URL もその値としてセルに表示されます。