Excel Office加载项API工作表保护密码

我有一个问题涉及Excel的工作表保护…

上下文是,我需要不同的工作表可供不同的用户组编辑,但所有组必须至less看到所有工作表,例如usergroup1可以编辑工作表二和三,部分工作表,usergroup2可以编辑只有工作表一。

我可以相应地设置FormatProtection( range.format.protection.locked = false; )和WorksheetProtection( worksheet.protection.protect(); )来启用这个function,但我似乎没有能力通过设置密码针对工作表保护的API? 这意味着,例如,任何一个组都可以简单地点击审阅function区中的取消保护页选项,并编辑我不想要的表。

我已经尝试过下面的文档,但不幸的是无济于事。

  • http://dev.office.com/reference/add-ins/excel/worksheetprotection
  • https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/worksheetprotection.md

作为一个例子,这是一个我想完成的function:

 function CopyWorksheet() { var newAddress; Excel.run(function (ctx) { var worksheet = ctx.workbook.worksheets.getActiveWorksheet(); var range = worksheet.getUsedRange(); range.load(); // insert new worksheet var newWorksheetName = "Copied_Sheet"; var newWorksheet = ctx.workbook.worksheets.add(newWorksheetName); return ctx.sync().then(function () { // copy the old values to the new worksheet newAddress = range.address.substring(range.address.indexOf("!") + 1); newWorksheet.getRange(newAddress).values = range.values; newWorksheet.getRange(newAddress).formulas = range.formulas; newWorksheet.getRange(newAddress).text = range.text; // protect both worksheets worksheet.protection.protect(); newWorksheet.protection.protect(); // requirement here to set a password so that no one can // edit the worksheets by selecting 'Unprotect Sheet' in excel // ... }) .then(ctx.sync)}) .catch(function(error) { console.log("Error: " + error); }); } 

目前,我正在使用Excel 2016(桌面版)。 这是可能实现,或者我错过了一些function,可以实现相同的结果吗?

谢谢你的帮助。

密码保护在我们的API中不可用。 您可以保护表单以避免不经意的编辑,但是您不能密码保护。 原因是密码保护在所有terminal上都不可用(IIRC,Excel Online有问题)。

如果你想在UserVoice上提出一个build议错误,你可以看看我们是否会考虑把密码保护作为一个仅限桌面的API。 到目前为止,我们已经避免在Excel中执行这些操作,但是我知道Word已经完成了一些“WordApiDesktop”API。 所以取决于它阻止你(和其他人)的情况,这可能是一个select。 在这种情况下,您可以在桌面上进行密码保护和取消保护,但无法在线执行这些操作。