对不起,我的英语。 我是新用户,我不太了解编程语言! :-)
我需要您的宝贵帮助。 我正在处理Google表单,我必须在该表单中注册客户才能选择他们的生日礼物。
在撰写本文之前,我在此处阅读了许多有关该主题的文章,但没有找到解决问题的方法。最接近的是:Overwriting Google sheets (for form response) rows if duplicate entered
我尝试运行找到的脚本,但是运行它们时出现了这个问题: TypeError:无法调用null的“ getSheetByName”方法。 (第16行,文件“ UPDATEcontact”)
工作表名称为:compleanno2020
function updateExisting(columnWithUniqueIdentifier,sheetTabName) {
var dataFromColumnToMatch,lastColumn,lastRow,rowWithExistingUniqueValue,rowOfDataJustSaved,sh,ss,valueToSearchFor;
// USER SETTINGS - if the values where not passed in to the function
if (!columnWithUniqueIdentifier) {//If you are not passing in the column number
columnWithUniqueIdentifier = 2;//Hard code column number if you want
}
if (!sheetTabName) {//The sheet tab name was not passed in to the function
sheetTabName = "compleanno2020";//Hard code if needed
}
//end of user settings
ss = Spreadsheetapp.getactiveSpreadsheet();//Get the active spreadsheet - this code must be in a project bound to spreadsheet
sh = ss.getSheetByName(sheetTabName);
lastRow = sh.getLastRow();
lastColumn = sh.getLastColumn();
//Logger.log('lastRow: ' + lastRow)
rowOfDataJustSaved = sh.getRange(lastRow,1,lastColumn).getvalues();//Get the values that were just saved
valueToSearchFor = rowOfDataJustSaved[0][columnWithUniqueIdentifier-1];
//Logger.log('valueToSearchFor: ' + valueToSearchFor)
dataFromColumnToMatch = sh.getRange(1,columnWithUniqueIdentifier,lastRow-1,1).getvalues();
dataFromColumnToMatch = dataFromColumnToMatch.toString().split(",");
//Logger.log('dataFromColumnToMatch: ' + dataFromColumnToMatch)
rowWithExistingUniqueValue = dataFromColumnToMatch.indexOf(valueToSearchFor);
//Logger.log('rowWithExistingUniqueValue: ' + rowWithExistingUniqueValue)
if (rowWithExistingUniqueValue === -1) {//There is no existing data with the unique identifier
return;
}
sh.getRange(rowWithExistingUniqueValue + 1,rowOfDataJustSaved[0].length).setvalues(rowOfDataJustSaved);
sh.deleteRow(lastRow);//delete the row that was at then end
}
我该怎么办: 我只想让客户注册一次-不激活登录-否则,如果我想将重复的数据覆盖,则不行。
要检查的变量绝对是电子邮件地址,但如果可能的话,应仔细检查,或与生日日期相关联的电子邮件地址。 在下面附上我的样本表。
您有什么解决方案吗? 我真的希望如此,并在此先感谢您。
谢谢大家。