The HyperLink CellType represents the hyperlink cell. You can add these types of cells to provide links to websites that users can click on to navigate to, which you can use in forms and other types of applications.
To create a hyperlink cell, use the following code:
var h = new GC.Spread.Sheets.CellTypes.HyperLink();
sheet.setCellType(3, 2, h, GC.Spread.Sheets.SheetArea.viewport);
You can use the text method to get and set the text string for the hyperlink. You can also set the tooltip that appears when the mouse pointer is over the hyperlink using the linkToolTip method. The following code uses these methods:
h.text('SpreadJS Site');
h.linkToolTip('This is the link to SpreadJS site');
Easily distinguish between visited and unclicked links by setting two different hyperlink colors for before and after clicking the hyperlink:
h.linkColor('red');
h.visitedLinkColor('blue');
After setting a hyperlink in a cell, you can control the text indent of the hyperlink by setting its textIndent property.
sheet.getCell(3, 2).textIndent(3);
Use the onClickAction method to set a callback to the hyperlink. Once you click on the link, the callback will be executed.
spread.commandManager().register('setSheetTabStyle', {
canUndo: true,
execute: function (context, options, isUndo) {
sheet.name('Hyperlink');
sheet.options.sheetTabColor = 'red';
}
}, null, false, false, false, false);
h.onClickAction(function () {
spread.commandManager().execute({cmd: 'setSheetTabStyle'});
});
Use the activeOnClick method to get and set whether to move to the active cell when clicked.
h.activeOnClick(true);
More options for hyperlink cellType:
After you set a hyperlink to a cell, you can set the value of the wordWrap property, which indicates whether to wrap the hyperlink.
sheet.getCell(3, 2).wordWrap(true); // default value of wordWrap is 'false.'
You can control the horizontal alignment of the hyperlink — which includes Left, Center, and Right — with the following code:
var hAlign = GC.Spread.Sheets.HorizontalAlign.right;
sheet.getCell(3, 2).hAlign(hAlign);
You can control the vertical alignment of the hyperlink — which includes Top, Center, and Bottom — with the following code:
var vAlign = GC.Spread.Sheets.VerticalAlign.bottom;
sheet.getCell(3, 2).vAlign(vAlign);
Submit and view feedback for