Доступ к объекту гиперссылки в ячейке GridWeb
Возможные сценарии использования
Вы можете проверить, содержит ли ячейка гиперссылку, используя следующие два метода. Эти методы вернут null, если ячейка не содержит гиперссылки, и если она содержит гиперссылку, то вернут объект GridHyperlink.
- GridHyperlinkCollection.getHyperlink(GridCell cell)
- GridHyperlinkCollection.getHyperlink(int row,int column)
Открыть гиперссылку в новом или существующем окне
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 the existing window. Besides, if you want to open the hyperlink in the existing window, then please set the GridHyperlink.Target to _self.
Доступ к объекту гиперссылки в ячейке GridWeb
В следующем примере кода осуществляется доступ к гиперссылке ячейки A1. Если ячейка A1 содержит гиперссылку, то будет возвращен объект GridHyperlink, в противном случае будет возвращено значение null.
Образец кода
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Access first worksheet of gridweb | |
GridWorksheet sheet = gridweb.getWorkSheets().get(0); | |
// Access cell A1 | |
GridCell cell = sheet.getCells().get("A1"); | |
// Access hyperlink of cell A1 if it contains any | |
GridHyperlink lnk = sheet.getHyperlinks().getHyperlink(cell); | |
if (lnk == null) { | |
// This cell does not have any hyperlink | |
} else { | |
// This cell does have hyperlink, access its properties e.g. address | |
String addr = lnk.getAddress(); | |
} |