我可以使用脚本锁定特定的Google Apps工作表吗?

PY_*_*PY_ 2 google-apps-script

有没有办法使用脚本锁定特定的Google Apps工作表?

我有这个代码将当前电子表格重命名为您在输入框中输入的内容.

// The code below will rename the active sheet to what you enter in the input box
var myValue = Browser.inputBox("Enter: LastMonth - Year");
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue);
SpreadsheetApp.getActiveSpreadsheet().getRange("A1").setValue(myValue);
Run Code Online (Sandbox Code Playgroud)

我可以添加到上面的代码中,这将锁定我刚刚重命名的相同工作表,只允许我编辑该工作表.那可能吗?

Sca*_*ael 6

// Enables sheet protection for  this sheet
var sheet = SpreadsheetApp.getActiveSheet();
var permissions = sheet.getSheetProtection();
permissions.setProtected(true);
sheet.setSheetProtection(permissions);
Run Code Online (Sandbox Code Playgroud)

请参阅电子表格服务 - 类PageProtection