Kom åt Hyperlink objektet för GridWeb cell
Möjliga användningsscenario
Du kan kontrollera om cellen innehåller en hyperlänk eller inte med hjälp av följande två metoder. Dessa metoder kommer att returnera null om cellen inte innehåller en hyperlänk, och om den innehåller en hyperlänk kommer den att returnera GridHyperlink-objekt.
- GridHyperlinkCollection.GetHyperlink(GridCell cell)
- GridHyperlinkCollection.GetHyperlink(int row,int column)
Öppna Hyperlänk i nytt eller befintligt fönster
If your excel file contains hyperlink which links to some URL like http://wwww.aspose.com/ and you load it in GridWeb then the hyperlinks will be rendered with target attribute set to _blank. It means, when you will click the hyperlink in a GridWeb cell, it will open up in a new window instead of existing window. Please check the GridHyperlink.Target property in the following debug window. Besides, if you want to open the hyperlink in the existing window, then please set the GridHyperlink.Target to _self.
Kom åt Hyperlink-objektet för GridWeb-cell
Följande exempelkod får åtkomst till hyperlänken för cell A1. Om cell A1 innehåller en hyperlänk kommer den att returnera GridHyperlink-objekt, annars kommer den att returnera null.
Exempelkod
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Access first worksheet of gridweb and cell A1 | |
GridWorksheet sheet = GridWeb1.WorkSheets[0]; | |
GridCell cellA1 = sheet.Cells["A1"]; | |
// Access hyperlink of cell A1 if it contains any | |
GridHyperlink cellHyperlink = sheet.Hyperlinks.GetHyperlink(cellA1); | |
if (cellHyperlink == null) | |
{ | |
Label1.Text = "Cell A1 does not have any hyperlink"; | |
} | |
else | |
{ | |
// Access hyperlink properties e.g. address | |
string hyperlinkAddress = cellHyperlink.Address; | |
Label1.Text = "Address of hyperlink in cell A1 :" + hyperlinkAddress; | |
} |