Spread表单

SpreadJS 包括多个表单, 表单名称标签, 滚动条等等。其核心部分是表单。你可以通过丰富的 API 定制自己的表单。

如果你想添加更多的表单来展现数据, 可以通过调用方法 addSheet 来添加表单。你可以只设置索引参数, 在所在位置添加一张空白的表单, 或者设置两个参数, 第二个参数是要添加的表单对象。例如: 你可以定制你的表单数量。 通过调用 getSheetCount 和 setSheetCount 方法获取或设置表单的数量。例如: 如果要修改活动表单,使用setActiveSheetIndex方法并为其提供对应的工作表的索引. 例如: 当你有了一个工作表的引用之后, 你可以自定义它,就像工作表示例中所展示的那样。 其他工作簿或着工作表相关的方法: addSheet: 在工作簿的指定位置添加特定的工作表。 getSheetCount: 获取工作簿中的工作表总数并使用它添加工作表。 removeSheet 和 clearSheets: 根据索引移除一个工作表并且清空所有的工作表。 getActiveSheetIndex: 获取活动工作表的索引。 changeSheetIndex: 修改活动工作表的索引。
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss')); var spreadNS = GC.Spread.Sheets; spread.setSheetCount(3); initSpread(spread); spread.bind(spreadNS.Events.ActiveSheetChanged, function(e, args) { _getElementById('activeSheetIndex').value = spread.getActiveSheetIndex(); _getElementById('changeSheetIndexName').value = spread.getActiveSheet().name(); }); _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() { var activeIndex = spread.getActiveSheetIndex(); if (activeIndex >= 0) { spread.removeSheet(activeIndex); spread.setActiveSheetIndex(activeIndex); } }); _getElementById('btnClearSheets').addEventListener('click',function() { spread.clearSheets(); }); _getElementById('btnSetActiveSheetIndex').addEventListener('click',function() { var index = _getElementById('activeSheetIndex').value; if (!isNaN(index)) { index = parseInt(index); if (0 <= index && index < spread.getSheetCount()) { spread.setActiveSheetIndex(index); } } }); _getElementById('btnChangeSheetIndex').addEventListener('click',function() { var sheetName = _getElementById('changeSheetIndexName').value; var targetIndex = _getElementById('changeSheetIndexTargetIndex').value; if (!isNaN(targetIndex)) { targetIndex = parseInt(targetIndex); if (0 <= targetIndex && targetIndex <= spread.getSheetCount()) { spread.changeSheetIndex(sheetName, targetIndex); } } }); }; function initSpread(spread) { } 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"> <div class="option-row"> <label>Use the below buttons to add, remove or clear all sheets from the current workbook.</label> </div> <div class="option-row"> <input type="button" value="Add Sheet" id="btnAddSheet" /> <input type="button" value="Remove Sheet" id="btnRemoveSheet" /> <input type="button" value="Clear Sheets" id="btnClearSheets" /> </div> <div class="option-row"> <label>ActiveSheetIndex:</label> <input type="text" id="activeSheetIndex" value="0" /> <input type="button" id="btnSetActiveSheetIndex" value="Set" /> </div> <div class="option-row"> <label>This switches the currently active sheet to the sheet at the specified index.</label> </div> <div class="option-row"> <label>ChangeSheetIndex</label> <label>Sheet Name:</label> <input type="text" id="changeSheetIndexName" value="Sheet1" /> <label>Target Index:</label> <input type="text" id="changeSheetIndexTargetIndex" value="2" /> <input type="button" id="btnChangeSheetIndex" value="Set" /> </div> </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: 3px; margin-top: 3px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; display: block; width: 100%; text-align: center; } input[type=text] { width: 230px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }