Excel Office 加载项 API 工作表保护密码
Excel Office Add-In API Worksheet Protection Password
我有一个关于 Excel 的工作sheet 保护的问题...
上下文是我需要为不同的用户组提供不同的工作sheet来编辑,但所有组必须至少看到所有 sheets 例如usergroup1 可以编辑 sheet 第二个和第三个以及 sheet 个的部分,usergroup2 只能编辑 sheet 个。
我可以相应地设置 FormatProtection (range.format.protection.locked = false;
) 和 WorksheetProtection (worksheet.protection.protect();
) 来启用它,但我似乎无法设置密码通过API对抗Worksheet保护?这意味着,例如,任何一组都可以简单地单击评论功能区中的取消保护 Sheet 选项并编辑我不希望他们编辑的 sheet。
我已尝试阅读以下文档,但不幸的是无济于事。
- http://dev.office.com/reference/add-ins/excel/worksheetprotection
- https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/worksheetprotection.md
例如,这是我想要完成的功能:
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(桌面版)。这是否可以实现,或者我错过了一些可以实现相同结果的现有功能?
感谢您的帮助。
密码保护在我们的 API 中不可用。您可以保护 sheet 以避免随意编辑,但不能使用密码保护。原因是并非所有端点都提供密码保护(IIRC,Excel 在线存在问题)。
如果您想在 UserVoice 上提交错误建议,您可以查看我们是否考虑将密码保护作为仅桌面 API。到目前为止,我们已经避免在 Excel 中执行这些操作,但我知道 Word 已经执行了一些 "WordApiDesktop" API。因此,根据它对您(和其他人)场景的阻塞程度,这可能是一种选择。在这种情况下,您可以在桌面上使用密码保护和取消保护,但无法在线执行这些操作。
此问题有更新:我们现在支持密码保护。检查 https://docs.microsoft.com/en-us/javascript/api/excel/excel.workbookprotection?view=office-js#protect-password-
我有一个关于 Excel 的工作sheet 保护的问题...
上下文是我需要为不同的用户组提供不同的工作sheet来编辑,但所有组必须至少看到所有 sheets 例如usergroup1 可以编辑 sheet 第二个和第三个以及 sheet 个的部分,usergroup2 只能编辑 sheet 个。
我可以相应地设置 FormatProtection (range.format.protection.locked = false;
) 和 WorksheetProtection (worksheet.protection.protect();
) 来启用它,但我似乎无法设置密码通过API对抗Worksheet保护?这意味着,例如,任何一组都可以简单地单击评论功能区中的取消保护 Sheet 选项并编辑我不希望他们编辑的 sheet。
我已尝试阅读以下文档,但不幸的是无济于事。
- http://dev.office.com/reference/add-ins/excel/worksheetprotection
- https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/worksheetprotection.md
例如,这是我想要完成的功能:
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(桌面版)。这是否可以实现,或者我错过了一些可以实现相同结果的现有功能?
感谢您的帮助。
密码保护在我们的 API 中不可用。您可以保护 sheet 以避免随意编辑,但不能使用密码保护。原因是并非所有端点都提供密码保护(IIRC,Excel 在线存在问题)。
如果您想在 UserVoice 上提交错误建议,您可以查看我们是否考虑将密码保护作为仅桌面 API。到目前为止,我们已经避免在 Excel 中执行这些操作,但我知道 Word 已经执行了一些 "WordApiDesktop" API。因此,根据它对您(和其他人)场景的阻塞程度,这可能是一种选择。在这种情况下,您可以在桌面上使用密码保护和取消保护,但无法在线执行这些操作。
此问题有更新:我们现在支持密码保护。检查 https://docs.microsoft.com/en-us/javascript/api/excel/excel.workbookprotection?view=office-js#protect-password-