If statement Google脚本if语句未检查用户与输入的数据
我在Google Sheets中有一个预订程序,用户可以选择自己的姓名(使用数据验证提供电子邮件列表),然后手机会受到保护,这样其他用户就不能更改预订 奇怪的是,一个人可以输入另一个人的电子邮件,然后手机会受到输入的电子邮件的保护,而不是用户。用户可以输入非电子邮件字符串,但不保护单元格 理想的结果是,如果用户的电子邮件和输入的数据相同,请保护单元格,否则可以自由编辑。 任何帮助都将不胜感激If statement Google脚本if语句未检查用户与输入的数据,if-statement,google-apps-script,google-sheets,If Statement,Google Apps Script,Google Sheets,我在Google Sheets中有一个预订程序,用户可以选择自己的姓名(使用数据验证提供电子邮件列表),然后手机会受到保护,这样其他用户就不能更改预订 奇怪的是,一个人可以输入另一个人的电子邮件,然后手机会受到输入的电子邮件的保护,而不是用户。用户可以输入非电子邮件字符串,但不保护单元格 理想的结果是,如果用户的电子邮件和输入的数据相同,请保护单元格,否则可以自由编辑。 任何帮助都将不胜感激 function onEdit(e){ var CurrentUser = Session.getE
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);
}
}
如果(CurrentUser=DataEntered)
需要
if(CurrentUser==DataEntered)
单个
=
将分配一个值,而不检查等效性。Wow。非常感谢。我尝试了==但它当时不起作用,但完全不知道===存在。是时候深入研究JavaScript了,但还有更多。