Hyperlink

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.

Description
app.vue
index.html
styles.css
Copy to CodeMine

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);
To create a hyperlink cell, use the following code: 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: Easily distinguish between visited and unclicked links by setting two different hyperlink colors for before and after clicking the hyperlink: After setting a hyperlink in a cell, you can control the text indent of the hyperlink by setting its textIndent property. Use the onClickAction method to set a callback to the hyperlink. Once you click on the link, the callback will be executed. Use the activeOnClick method to get and set whether to move to the active cell when clicked. 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. You can control the horizontal alignment of the hyperlink — which includes Left, Center, and Right — with the following code: You can control the vertical alignment of the hyperlink — which includes Top, Center, and Bottom — with the following code:
<template> <div class="sample-tutorial"> <gc-spread-sheets class="sample-spreadsheets" @workbookInitialized="initSpread"> <gc-worksheet></gc-worksheet> </gc-spread-sheets> <div class="options-container"> <div class="option-row"> <label for="linkColor">Link Color:</label> <input id="linkColor" type="text" v-model="linkColor" /> </div> <div class="option-row"> <label for="visitedLinkColor">Visited Link Color:</label> <input id="visitedLinkColor" type="text" v-model="visitedLinkColor" /> </div> <div class="option-row"> <label for="text">Text:</label> <input id="text" type="text" v-model="text" /> </div> <div class="option-row"> <label for="linkToolTip">Link Tooltip:</label> <input id="linkToolTip" type="text" v-model="linkToolTip" /> </div> <div class="option-row"> <input type="button" id="setProperty" value="Update" :disabled="disabled" @click="propertyChange($event, true)" /> </div> </div> </div> </template> <script> import Vue from "vue"; import "@mescius/spread-sheets-vue"; import GC from "@mescius/spread-sheets"; import "./styles.css"; const spreadNS = GC.Spread.Sheets; let App = Vue.extend({ name: "app", data: function() { return { linkColor: '', visitedLinkColor: '', text: '', linkToolTip: '', disabled: false, spread: null }; }, methods: { initSpread(spread) { this.spread = spread; const sheet = spread.getActiveSheet(); sheet.bind(spreadNS.Events.SelectionChanged, (e) => { this.propertyChange(e); }); sheet.suspendPaint(); sheet.setColumnWidth(2, 130); sheet.setColumnWidth(1, 120); sheet.setRowHeight(1, 50); //set a hyperlink CellType to a cell const h1 = new spreadNS.CellTypes.HyperLink(); h1.text("SpreadJS Overview"); sheet.setCellType(1, 2, h1, spreadNS.SheetArea.viewport); sheet.getCell(1, 2, spreadNS.SheetArea.viewport).value("http://developer.mescius.com/en/spreadjs/").hAlign(spreadNS.HorizontalAlign.left); sheet.setValue(1, 1, "basic hyperlink:"); const h2 = new GC.Spread.Sheets.CellTypes.HyperLink(); //set callback to h2 const h = this.setCellTypeCallback(h2); sheet.setCellType(3, 2, h); sheet.getCell(3, 1, GC.Spread.Sheets.SheetArea.viewport).value("hyperLink callback:").hAlign(GC.Spread.Sheets.HorizontalAlign.left); sheet.resumePaint(); spread.commandManager().register("setSheetTabStyle", { canUndo: true, execute: () => { sheet.name("Hyperlink"); sheet.options.sheetTabColor = "red"; } }, null, false, false, false, false); }, propertyChange(e, settings) { const sheet = this.spread.getActiveSheet(); const sels = sheet.getSelections(); if (sels && sels.length > 0) { const sel = this.getActualRange(sels[0], sheet.getRowCount(), sheet.getColumnCount()); const hyperLinkCellType = sheet.getCellType(sel.row, sel.col); if (!(hyperLinkCellType instanceof spreadNS.CellTypes.HyperLink)) { this.disabled = true; return; } if (!settings) { this.disabled = false; this.linkColor = hyperLinkCellType.linkColor(); this.visitedLinkColor = hyperLinkCellType.visitedLinkColor(); this.text = hyperLinkCellType.text(); this.linkToolTip = hyperLinkCellType.linkToolTip(); } else { hyperLinkCellType.linkColor(this.linkColor); hyperLinkCellType.visitedLinkColor(this.visitedLinkColor); hyperLinkCellType.text(this.text); hyperLinkCellType.linkToolTip(this.linkToolTip); } } sheet.repaint(); }, getActualRange(range, maxRowCount, maxColCount) { const row = range.row < 0 ? 0 : range.row; const col = range.col < 0 ? 0 : range.col; const rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; const colCount = range.colCount < 0 ? maxColCount : range.colCount; return new spreadNS.Range(row, col, rowCount, colCount); }, setCellTypeCallback(h) { h.text("set sheet tab style"); h.linkToolTip("set sheet tab style and sheet name"); h.activeOnClick(true); h.onClickAction(() => { this.spread.commandManager().execute({cmd: "setSheetTabStyle"}); }); return h; } } }); new Vue({ render: h => h(App) }).$mount("#app"); </script>
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/vue/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/vue/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); System.import('$DEMOROOT$/en/lib/vue/license.js'); </script> </head> <body> <div id="app"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; overflow: auto; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; } .option-row { padding-bottom: 12px; } label { padding-bottom: 6px; display: block; } input, select { width: 100%; padding: 4px 8px; box-sizing: border-box; } input[type=checkbox] { width: auto; } input[type=checkbox]+label { display: inline-block; width: auto; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' }, '*.vue': { loader: 'vue-loader' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-vue': 'npm:@mescius/spread-sheets-vue/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'css': 'npm:systemjs-plugin-css/css.js', 'vue': 'npm:vue/dist/vue.min.js', 'vue-loader': 'npm:systemjs-vue-browser/index.js', 'tiny-emitter': 'npm:tiny-emitter/index.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' } } }); })(this);