多表单选择

用户可以使用Shift / Ctrl / Cmd键并单击表单标签以选择或取消选择多个工作表的表单选择状态。这是与Excel匹配的默认SpreadJS行为。此外,你也可以使用isSelected 方法来选择和取消选择多个工作表。

你可以通过isSelected方法来获取或设置一个表单的选择状态,例如: 活动工作表始终处于选中状态,不能设置为未选中状态。 如果使用isSelected方法将活动工作表设置为未选中,则活动但未选中的工作表将具有另一个工作表标签视图。 您还可以通过使用Shift / Ctrl键单击来更改一个或多个表单的选定状态(在MacOS中,您需要使用Shift / Command键) 当更改工作表的选定状态时,Spread还提供两个事件: Spread支持批量删除和隐藏多个选定工作表的功能。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 5 }); initCheckBoxesEvent(spread); initSpread(spread); }; function initCheckBoxesEvent(spread) { var sheetsNames = ["Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5"]; sheetsNames.forEach(function (name) { document.getElementById(name).addEventListener('change', function (e) { var sheet = spread.getSheetFromName(name); if (sheet) { sheet.isSelected(this.checked); spread.repaint(); } }); }); } function initSpread(spread) { var sheet1 = spread.getSheetFromName("Sheet1"); var sheet2 = spread.getSheetFromName("Sheet2"); var sheet3 = spread.getSheetFromName("Sheet3"); sheet1.isSelected(true); sheet2.isSelected(true); sheet3.isSelected(true); spread.bind(GC.Spread.Sheets.Events.SheetChanged, function (e, args) { var checkboxElement = document.getElementById(args.sheetName); if (checkboxElement) { checkboxElement.checked = !checkboxElement.checked; } }); spread.repaint(); } 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$/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"> <p>Click the checkbox to select or deselect the sheet.</p> <p>Hold down the Shift/Ctrl/Cmd key and click the sheet tab to select/deselect multiple sheets. The sheet checkbox will update correspondingly.</p> </div> <div class="sheets-checkboxes-container"> <div class="option-row"> <input type="checkbox" id="Sheet1" checked /> <label for="Sheet1" id="labelOfSheet1">Sheet1</label> </div> <div class="option-row"> <input type="checkbox" id="Sheet2" checked /> <label for="Sheet2" id="labelOfSheet2">Sheet2</label> </div> <div class="option-row"> <input type="checkbox" id="Sheet3" checked /> <label for="Sheet3" id="labelOfSheet3">Sheet3</label> </div> <div class="option-row"> <input type="checkbox" id="Sheet4" /> <label for="Sheet4" id="labelOfSheet4">Sheet4</label> </div> <div class="option-row"> <input type="checkbox" id="Sheet5" /> <label for="Sheet5" id="labelOfSheet5">Sheet5</label> </div> </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; } .sheets-checkboxes-container { padding-left: 10px; } label { margin-bottom: 6px; } input { padding: 4px 6px; } hr { border-color: #fff; opacity: .2; margin-top: 20px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }