不加载Excel时保护功能正常,一加载Excel保护功能就不行了,有兄弟帮忙看一下吗?谢谢!
- <body>
- <div class="content-container">
- <div id="inner-content-container">
- <table id="formulaBar" style="width: 100%;">
- <tbody>
- <tr>
- <td style="vertical-align:top;">
- <input type="text" id="positionbox" disabled="disabled" style="/*text-align: center;*/ padding: 5px; border-width: 0; background-color: rgb(235, 235, 228); height: 36px;">
- </td>
- <td style="width: 100%; border-left: 1px solid #ccc;">
- <div id="formulabox" contenteditable="true" spellcheck="false" style="overflow: hidden; height: 36px; width: 100%; padding: 9px;"></div>
- <div class="vertical-splitter ui-draggable" id="verticalSplitter"></div>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="spread-container" id="controlPanel" style="height: 600px; bottom: 0;">
- <div id="ss" style="height: 100%; border: 1px solid #ddd;"></div>
- </div>
- </div>
- </div>
- <div style="margin-bottom:100px;">
- <input type="button" value="导出excel" id="download" onclick="exportToExcel();">
- <input id="chkProtectSheet" type="checkbox" />
- <label for="chkProtectSheet">Protect Sheet</label>
- <input id="chkSelectUnlockedCells" type="checkbox" checked="checked" />
- <label for="chkSelectUnlockedCells">Select unlocked cells</label>
- <div class="option-row">
- <input id="chkAllowResizeRows" type="checkbox" />
- <label for="chkAllowResizeRows">Resize rows</label>
- <input id="chkAllowResizeColumns" type="checkbox" />
- <label for="chkAllowResizeColumns">Resize columns</label>
- </div>
- <div class="option-row">
- <input type="button" value="Set" id="setProtectionOptions" style="width:100px;" />
- <label style="width: 60%;">Select the Protection options and then click Set</label>
- </div>
-
- </div>
- </body>
复制代码- $(document).ready(function() {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {
- sheetCount: 1
- });
- initSpread(spread);
- TestSpread(spread);
- });
- function initSpread(spread) {
- fbx = new spreadNS.FormulaTextBox.FormulaTextBox(document.getElementById('formulabox'));
- fbx.workbook(spread);
-
- GC.Spread.Common.CultureManager.culture("zh-cn");
- var excelIo = new GC.Spread.Excel.IO();
- var excelFilePath = '/全自动变比测试仪测试版.xlsx';
- var xhr = new XMLHttpRequest();
- xhr.open('GET', excelFilePath, true);
- xhr.responseType = 'blob';
- xhr.onload = function (e) {
- if (this.status == 200) {
- var blob = this.response;
- // convert Excel to JSON
- excelIo.open(blob, function (json) {
- var workbookObj = json;
- spread.fromJSON(workbookObj);
- spread.suspendPaint();
- //spread.removeSheet(0);
- spread.setActiveSheetIndex(1);
- spread.resumePaint();
- }, function (e) {
- // process error
- alert(e.errorMessage);
- }, {});
- }
- };
- xhr.send();
- }
- function TestSpread(spread) {
- var sheet = spread.getActiveSheet();
- var option = {
- allowFilter: true,
- allowSort: false,
- allowResizeRows: true,
- allowResizeColumns: false,
- allowEditObjects: false
- };
- sheet.options.protectionOptions = option;
- sheet.options.isProtected = true;
- option = sheet.options.protectionOptions;
- $("#chkProtectSheet").prop("checked", sheet.options.isProtected);
- $("#chkSelectLockedCells").prop("checked", option.allowSelectLockedCells);
- $("#chkSelectUnlockedCells").prop("checked", option.allowSelectUnlockedCells);
- $("#chkAllowSort").prop("checked", option.allowSort);
- $("#chkAllowFilter").prop("checked", option.allowFilter);
- $("#chkAllowResizeRows").prop("checked", option.allowResizeRows);
- $("#chkAllowResizeColumns").prop("checked", option.allowResizeColumns);
- $("#chkAllowEditObjects").prop("checked", option.allowEditObjects);
- $("#chkProtectSheet").click(function() {
- var sheet = spread.getActiveSheet();
- var value = $(this).prop("checked");
- sheet.options.isProtected = value;
- });
- $("#setProtectionOptions").click(function() {
- var option = {
- allowSelectLockedCells: $("#chkSelectLockedCells").prop("checked"),
- allowSelectUnlockedCells: $("#chkSelectUnlockedCells").prop("checked"),
- allowSort: $("#chkAllowSort").prop("checked"),
- allowFilter: $("#chkAllowFilter").prop("checked"),
- allowResizeRows: $("#chkAllowResizeRows").prop("checked"),
- allowResizeColumns: $("#chkAllowResizeColumns").prop("checked"),
- allowEditObjects: $("#chkAllowEditObjects").prop("checked")
- };
- var sheet = spread.getActiveSheet();
- sheet.options.protectionOptions = option;
- });
- }
复制代码
|
|