我想以某种方式自动锁定我的Google表格单元格,以便每天在特定时间自动锁定。我应该可以编辑它,但不能编辑我的合作者。
如何解决此问题?
在样本表( link here )中,您将看到某些日期(15/7 / 2015-17 / 7/2015)。我想对其进行编码,以便每天晚上10点锁定每个日期(例如A1:B6
)。
答案 0 :(得分:10)
作为@NightShadeQueen suggested,可以使用Time-driven triggers和protect()-method of the Class Range的组合。
如果您的工作表看起来不像样本表,则必须修改代码。特别是lockRanges()
- 函数,它定义了应该保护的范围。目前,它从单元格A1
开始,一次向下逐行7行,直到达到工作表的末尾。
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);
}
}
Run
= lockRanges
Events
= Time-driven
,Day timer
,10pm to 11pm
(或随时随地)注意:时间可能稍微随机(read more)
就是这样,现在范围将在您选择时受到保护。与手动保护的范围一样,它们显示在数据&gt;中。受保护的工作表和范围。
有些不清楚?提问!