Get Set Data

SpreadJS offers many methods through the sheet to work with the cell's data.

You can get or set a value for a specified cell. To get a series of values or set values to a range of cells, you can use code similar to the following: You can also get or set text to a specified cell. This is similar to getting or setting a value to a cell. If you want to delete data, you can use the following method to clear the data from the specified range. SpreadJS also supports copying or moving a series of data from one range to another range.
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss')); var spreadNS = GC.Spread.Sheets; var sheet = spread.getSheet(0); sheet.suspendPaint(); sheet.setValue(1, 1, 'setValue'); sheet.setValue(1, 2, 2014); sheet.setText(3, 1, 'setText'); sheet.setText(3, 2, '01/01/2014'); sheet.setColumnWidth(2, 90); sheet.setColumnWidth(3, 100); sheet.setColumnWidth(4, 100); sheet.setValue(5, 1, 'setArray'); sheet.setArray(5, 2, [ [ 'ID', 'Phone Number', 'Address' ], [ 1, '021-432378', 'Marbury Road' ], [ 2, '021-432668', 'Chester Road' ], [ 3, '021-432238', 'Gertt Road' ], [ 4, '021-432533', 'Jnyliner Road' ], [ 5, '021-432125', 'Approach Road' ], [ 6, '021-432789', 'Jones Road' ] ]); document.getElementById('btnCopy').addEventListener('click', function() { sheet.copyTo(5, 4, 5, 7, 7, 1, spreadNS.CopyToOptions.all); }); document.getElementById('btnMove').addEventListener('click', function() { sheet.moveTo(5, 2, 5, 5, 7, 2, spreadNS.CopyToOptions.all); }); sheet.resumePaint(); };
<!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/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <p>User can set the data for the worksheet or get the data from sheet.</p> <p>Clicking "Copy" button will copy the data from E6:E12 to H6:H12.</p> <p>Clicking "Move" button will move the data from C6:D12 to F6:G12.</p> <input type="button" value="Copy" id="btnCopy" /> <input type="button" value="Move" id="btnMove" /> </div> </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; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } label { display: block; margin-bottom: 6px; margin-top: 6px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }