如何将selectionMode设置为Unlocked? Excel加载项Office.js

时间:2019-10-18 08:02:38

标签: excel office-js excel-addins

我有一个小的Excel加载项,用office.js编写,并使用Visual Studio2019。无论如何,我都无法获得该加载项来保护工作表并仅允许用户选择未锁定的单元格。

我一直用Google搜索直到眼睛流血,最好的使用示例是this one。这包含很多选项,但不是我想要的!

Microsoft文档为here

function ProtectSheet() {
     Excel.run(function (context) {
          var sheet = context.workbook.worksheets.getItem("Sheet1");
          sheet.protection.protect(); //works fine, obviously doesn't achieve what I want

          //here's the formats I've tried:
          sheet.protection.protect({ SelectionMode: "Unlocked" });
          sheet.protection.protect({ SelectionMode: unlocked });
          sheet.protection.protect({ SelectionMode: Excel.ProtectionSelectionMode "Unlocked" });
          sheet.protection.protect({ SelectionMode: Excel.ProtectionSelectionMode unlocked });
          sheet.protection.protect({ SelectionMode?: "Unlocked" });
          sheet.protection.protect({ SelectionMode?: unlocked });
          sheet.protection.protect({ SelectionMode?: Excel.ProtectionSelectionMode "Unlocked" });
          sheet.protection.protect({ SelectionMode?: Excel.ProtectionSelectionMode unlocked });

// all of the rest just compile to sheet.protection.protect() when viewing in the debugger;

          return context.sync();
     })
}

工作表受到保护,但未设置仅选择未使用的单元格的选项。

谢谢!

1 个答案:

答案 0 :(得分:0)

能否请您尝试如下设置解锁模式:

sheet.protection.protect("Unlocked");