我在Google表格中有一个预订程序,用户可以在其中选择他们的名字(使用数据验证来提供电子邮件列表),然后将单元格置于保护状态,以便其他用户无法更改预订。
发生的奇怪事情是,一个人可以输入另一个人的电子邮件,然后该单元格受到输入的电子邮件而不是用户的保护。用户可以输入非电子邮件字符串,但不保护单元格。
期望的结果是,如果用户的电子邮件和输入的数据相同,则保护单元格,否则可以自由编辑。
任何帮助将不胜感激!
function onEdit(e){
var CurrentUser = Session.getEffectiveUser().getEmail()
var range_DataEntered = SpreadsheetApp.getActiveRange();
var DataEntered = range_DataEntered.getValue();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var SheetName = SpreadsheetApp.getActiveSheet();
var Cell = ss.getActiveCell();
if (CurrentUser = DataEntered) {
var protection = range_DataEntered.protect()
// 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.
protection.addEditor(CurrentUser);
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
else {
//remove protection, set everyone to edit
range_DataEntered.protect().setDomainEdit(true);
}
}
答案 0 :(得分:0)
if (CurrentUser = DataEntered)
需要
if(CurrentUser === DataEntered)
单个=
将分配一个值,而不是检查是否等效。