SpreadJS provides cell types. It can support two-way binding (data changes in the view model are reflected in the view). Each cell type provides two modes: display mode and edit mode. These cell types allow you to customize the way that specific cells behave, and gives you control over the different types of input that you might want for your application.

To set the cell type, first create a cellType object, then use the setCellType method to set the cellType for the sheet, cell, column, or row. For example: Sometimes you can use the cellType with data binding by binding a cellType to a column. For example: After you set the cell type you can use the getCellType method to get the cell type. If you want to remove the cell type, set the value to null or undefined. SpreadJS provides an event (ButtonClicked) on the spreadsheet. The event occurs when you click a button, check box, or hyperlink in a cell. For example:
// @ts-ignore import { Component, NgModule, enableProdMode } from '@angular/core'; // @ts-ignore import { BrowserModule } from '@angular/platform-browser'; // @ts-ignore import { FormsModule } from '@angular/forms'; // @ts-ignore import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; // @ts-ignore import { SpreadSheetsModule } from '@grapecity/spread-sheets-angular'; // @ts-ignore import GC from '@grapecity/spread-sheets'; import { getData } from "./app.data"; import './styles.css'; const spreadNS = GC.Spread.Sheets; @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { spread: GC.Spread.Sheets.Workbook; hostStyle = { width: 'calc(100% - 280px)', height: '100%', overflow: 'hidden', float: 'left' }; datasource = getData(); message = ''; sheet: GC.Spread.Sheets.Worksheet; initSpread($event: any) { const spread = $event.spread; const GCsheets = GC.Spread.Sheets; const sheet = spread.getSheet(0); spread.bind(GCsheets.Events.ButtonClicked, (e: MouseEvent, args: any) => { const { sheet, row, col } = args; const cellType = sheet.getCellType(row, col); if (cellType instanceof GCsheets.CellTypes.Button) { this.message += "You click a button.\n"; } if (cellType instanceof GCsheets.CellTypes.CheckBox) { this.message += "You click a check box.\n"; } if (cellType instanceof GCsheets.CellTypes.HyperLink) { this.message += "You click a hyperlink.\n"; } }); spread.bind(GCsheets.Events.CellClick, (e: MouseEvent, args: any) => { const { sheet, row, col } = args; const cellType = sheet.getCellType(row, col); if (cellType instanceof GCsheets.CellTypes.ComboBox) { this.message += "You click a combo box.\n"; } }); sheet.suspendPaint(); sheet.name('Basic Usage'); sheet.setColumnWidth(2, 140); sheet.setColumnWidth(1, 120); sheet.setRowHeight(1, 50); const b0 = new GCsheets.CellTypes.Button(); b0.text("Margin"); b0.marginLeft(15); b0.marginTop(7); b0.marginRight(15); b0.marginBottom(7); sheet.setCellType(1, 2, b0, GCsheets.SheetArea.viewport); sheet.setValue(1, 1, "ButtonCellType"); const c = new GCsheets.CellTypes.CheckBox(); c.isThreeState(false); c.textTrue("Checked!"); c.textFalse("Check Me!"); sheet.setCellType(2, 2, c, GCsheets.SheetArea.viewport); sheet.setValue(2, 1, "CheckBoxCellType"); const combo = new GCsheets.CellTypes.ComboBox(); combo.items([{ text: "Oranges", value: "11k" }, { text: "Apples", value: "15k" }, { text: "Grape", value: "100k" }]); combo.editorValueType(GCsheets.CellTypes.EditorValueType.text); sheet.getCell(3, 2, GCsheets.SheetArea.viewport).cellType(combo).value("Grape"); sheet.setValue(3, 1, "ComboBoxCellType"); const h = new GCsheets.CellTypes.HyperLink(); h.text("SpreadJS Overview"); sheet.setCellType(4, 2, h, GCsheets.SheetArea.viewport); sheet.getCell(4, 2, GCsheets.SheetArea.viewport).value("http://www.grapecity.com/en/spreadjs/").hAlign(GCsheets.HorizontalAlign.center); sheet.setValue(4, 1, "HyperLinkCellType"); sheet.resumePaint(); const sheet1 = spread.getSheet(1); sheet1.name('DataBind'); sheet1.suspendPaint(); const _lines = ["Computers", "Washers", "Stoves"]; const _colors = ["Red", "Green", "Blue", "White"]; const _ratings = ["Terrible", "Bad", "Average", "Good", "Great", "Epic"]; const lineCellType = new GCsheets.CellTypes.ComboBox(); lineCellType.items(_lines); const colorCellType = new GCsheets.CellTypes.ComboBox(); colorCellType.items(_colors); const checkBoxCellType = new GCsheets.CellTypes.CheckBox(); const ratingCellType = new GCsheets.CellTypes.ComboBox(); ratingCellType.items(_ratings); const colInfos = [ { name: "name", size: 100 }, { name: "line", cellType: lineCellType, size: 80 }, { name: "color", cellType: colorCellType }, { name: "discontinued", cellType: checkBoxCellType, size: 80 }, { name: "rating", cellType: ratingCellType } ]; sheet1.bindColumns(colInfos); sheet1.resumePaint(); } } @NgModule({ imports: [BrowserModule, SpreadSheetsModule, FormsModule], declarations: [AppComponent], exports: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule);
<!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/angular/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- Polyfills --> <script src="$DEMOROOT$/en/angular/node_modules/core-js/client/shim.min.js"></script> <script src="$DEMOROOT$/en/angular/node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="$DEMOROOT$/en/angular/node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('$DEMOROOT$/en/lib/angular/license.ts'); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html>
<div class="sample-tutorial"> <gc-spread-sheets [hostStyle]="hostStyle" (workbookInitialized)="initSpread($event)"> <gc-worksheet></gc-worksheet> <gc-worksheet [dataSource]="datasource" [autoGenerateColumns]="autoGenerateColumns"></gc-worksheet> </gc-spread-sheets> <div class="options-container"> This text box will display information about the different cell types that are interacted with. <div class="option-row"> <textarea id="eventTrigger" style="width: 100%; height: 120px" [(ngModel)]="message"></textarea> </div> </div> </div>
export function getData() { return [ { name: "Stoves S0", line: "Washers", color: "Green", discontinued: true, rating: "Average" }, { name: "Computers C1", line: "Washers", color: "Green", discontinued: true, rating: "Average" }, { name: "Washers W3", line: "Washers", color: "Green", discontinued: true, rating: "Average" } ] }
.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; } .sample-options{ z-index: 1000; } .option { padding-bottom: 6px; } .checkbox { padding-right: 12px; display: inline-block; } label { display: inline-block; min-width: 100px; } input, select { width: 100%; padding: 4px 0; margin-top: 4px; box-sizing: border-box; } input[type=checkbox] { width: auto; padding: 0; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'ts', typescriptOptions: { tsconfig: true }, meta: { 'typescript': { "exports": "ts" }, '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'core-js': 'npm:core-js/client/shim.min.js', 'zone': 'npm:zone.js/dist/zone.min.js', 'rxjs': 'npm:rxjs/bundles/rxjs.umd.min.js', '@angular/core': 'npm:@angular/core/bundles/core.umd.min.js', '@angular/common': 'npm:@angular/common/bundles/common.umd.min.js', '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.min.js', '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.min.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js', '@angular/http': 'npm:@angular/http/bundles/http.umd.min.js', '@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.min.js', '@angular/router': 'npm:@angular/router/bundles/router.umd.min.js', '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.min.js', 'jszip': 'npm:jszip/dist/jszip.min.js', 'typescript': 'npm:typescript/lib/typescript.js', 'ts': 'npm:plugin-typescript/lib/plugin.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js', '@grapecity/spread-sheets': 'npm:@grapecity/spread-sheets/index.js', '@grapecity/spread-sheets-angular': 'npm:@grapecity/spread-sheets-angular/bundles/grapecity-spread-sheets-angular.umd.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'ts' }, rxjs: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);