初始化表单

你可以在Spread.Sheets中添加一个或多个表单。

使用下面的步骤来引用Spread,然后和表单一起工作。 与其他组件类似, 表单需要以下文件: gc.spread.sheets.x.x.x.css gc.spread.sheets.all.x.x.x.min.js 通过以下代码构造一个新的表单(参数为表单的名字)。 通过以下代码将表单实例插入到 Spread 控件的指定索引位置。 如果你想从 Spread 控件上删除一个表单, 可以通过以下代码. 示例代码展示从 Spread 控件删除第一个表单。 如果你想从 Spread 控件上删除所有的表单, 可以调用 clearSheets 方法。 如果你想自定制表单的名字, 可以调用 name 方法来获取和设置表单的名字。
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss')); initSpread(spread); _getElementById('btnAddSheet').addEventListener('click', function() { var activeIndex = spread.getActiveSheetIndex(); if (activeIndex >= 0) { spread.addSheet(activeIndex+1); spread.setActiveSheetIndex(activeIndex+1); } else{ spread.addSheet(0); spread.setActiveSheetIndex(0); } }); _getElementById('btnRemoveSheet').addEventListener('click', function() { if (spread.getSheetCount() > 0) { spread.removeSheet(spread.getActiveSheetIndex()); } }); _getElementById('btnClearSheets').addEventListener('click', function() { spread.clearSheets(); }); }; function initSpread(spread) { var sheet = spread.getActiveSheet(); } function _getElementById(id) { return document.getElementById(id); }
<!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-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/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-software/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" class="sample-spreadsheets"></div> <div class="options-container"> Adds a sheet after the active one <input type="button" value="Add Sheet" id="btnAddSheet" /> <br> Removes the active sheet <input type="button" value="Remove Sheets" id="btnRemoveSheet" /> <br> Clears all the sheets from the workbook <input type="button" value="Remove All Sheets" id="btnClearSheets"/> </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; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }