初始化Spread

此示例演示如何创建Spread.Sheets工作簿组件,还说明如何从初始化的工作簿主机DOM元素中获取组件实例。

SpreadJS 不依赖于任何第三方类库,初始化仅需要以下文件: gc.spread.sheets.x.x.x.css gc.spread.sheets.all.x.x.x.min.js 将 gc.spread.sheets.x.x.x.css 和 gc.spread.sheets.all.x.x.x.min.js 文件加入到 HTML 文档 Head 部分并给予其对应路径。例如: Spread 控件通过 new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 }), 函数进行初始化, 并且 spread ( 以下简称 SpreadJS 控件为 'spread') 被添加到 id 为 'ss' 的 Div 元素中。你可以通过函数 var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'))获取 spread对象实例。然后, 你就可以定制你的 spread 了。 例如: 当然,你仍可以配合jQuery来操作SpreadJS, 例如:
window.onload = function () { // host the workbook control in a DIV element with id "ss" var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 }); /* * retrieve the spread workbook object from the host element using findControl static method. * var spread = GC.Spread.Sheets.findControl(document.getElementById('ss')); */ initSpread(spread); }; function initSpread(spread) { var sheet = spread.getActiveSheet(); //Add text to first cell sheet.setValue(0, 0, "Hello World!"); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/data.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.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" style="width:100%;height:100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }