我在线使用Office 365和Excel(Build 16.0.9403.1875)。
我正在使用Add-ins在线创建Microsoft Excel Excel javascript API。
除了少数单元格(Range)之外,我还需要对整张表格进行写保护。
所以,我提到Format protection API,但在调试时,'locked'属性在行动中没有效果。
我提到过,使用此link
也会叠加流量至于,我已经尝试过上述论坛链接提供的建议。
我只希望通过工作代码片段来回复。
我的代码示例在
之下 Excel.run(function (ctx) {
//Worksheet
var sheet = ctx.workbook.worksheets.getItem("Sheet1");
//Entire Range
var entireRange = sheet.getRange();
entireRange.format.protection.locked = false;
//Specific Range
var range = sheet.getRange("A1:B5");
return ctx.sync()
.then(() => {
//Set specific range "locked" status to true.
range.format.protection.locked = true;
})
.then(ctx.sync)
.then(() => {
//Protect Entire sheet
sheet.protection.protect({
allowInsertRows: false,
allowDeleteRows: false
});
});
}).catch(errorHandler);
感谢。