简体   繁体   English

如何将 selectionMode 设置为 Unlocked? Excel 插件,Office.js

[英]How to set selectionMode to Unlocked? Excel add-in, Office.js

I have a small excel add-in, written in office.js and using Visual Studio 2019. Whatever I do, I can't get the add-in to protect the worksheet and allow the user to only select unlocked cells.我有一个小的 excel 加载项,用 office.js 编写并使用 Visual Studio 2019。无论我做什么,我都无法获得加载项来保护工作表并只允许用户使用 select 解锁单元格。

I've googled till my eyes bleed, best example for use is this one .我已经用谷歌搜索到我的眼睛流血了,最好的例子就是这个 This contains many options, but not the one I want!这包含许多选项,但不是我想要的!

Microsoft documentation is here . Microsoft 文档在此处

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();
     })
}

The sheet is protected, but the option to select only unused cells is not set.工作表受到保护,但未设置 select 的选项,仅未使用的单元格。

Thanks in advance!提前致谢!

Can you please try to set Unlock mode like below:您能否尝试设置解锁模式,如下所示:

sheet.protection.protect("Unlocked");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Office.JS:如何使用Office 2016 OnPrem加载Word / Excel任务窗格加载项? - Office.JS: How to sideload Word/Excel Taskpane add-in with Office 2016 OnPrem? 如何私下分发 excel office 插件(w/office.js)? - How do I distribute excel office add-in(w/ office.js) in privately? 将 Office.js(Excel 加载项)连接到 SQL Server - Connect Office.js (Excel Add-in) to SQL Server 使用 Office.js 从 Excel 加载项创建 Word 文档 - Creating Word document from Excel Add-In with Office.js 分发由 Web 加载项 (office.js) 提供支持的 Excel 工作簿 - Distribute Excel workbook powered by web add-in (office.js) 在office.js Excel加载项中为单个列设置列宽 - Set column width for a single column in office.js excel add-in Microsoft office.js Excel 插件 - 如何为折线图中的数据系列实现箭头样式? - Microsoft office.js Excel add-in - How to implement arrow style for a data series in a line chart? 如何编写和测试Office.js外接程序的动态服务器? - How to write and test dynamic server for Office.js add-in? Office Professional 2016 Excel Office.js 插件浏览器问题 - Office Professional 2016 Excel Office.js Add-in Browser Issue 如果工作表名称中带有连字符(-),则Office.js Excel加载项命名绑定将不起作用 - Office.js Excel add-in named binding does not works if we have a hyphen(-) in the sheet name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM