我需要每天下午 5 点到 6 点将谷歌表格锁定为只读模式。我们有实现这一目标的设置吗?我在 StackOverflow 中看到了几个答案,但其中大部分是锁定单元格
我按照下面的脚本创建了一个时间驱动的触发器。它说执行完成。但我仍然可以在我的工作表上写字。
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1'); //INSERT SHEET NAME HERE
function lockRanges() {
//First cell to lock
var row = 1;
var col = 1;
// Get last row with data in sheet
var lastRow = sheet.getLastRow();
//Loop until last row in sheet is passed
while(row <= lastRow){
//Lock current cell
lockRange(row, col);
// Go to row 7 steps down from current (the next date)
row = row + 7;
}
}
function lockRange(row, col){
var range = sheet.getRange(row, col);
// Create protection object. Set description, anything you like.
var protection = range.protect().setDescription('Protected, row ' + row);
// Ensure the current user is an editor before removing others. Otherwise, if the user's edit
// permission comes from a group, the script will throw an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}