问题描述
好的,我有一个Google表单,上面有一些要输入的内容,例如员工代码。当有人输入验证码时,我需要将此验证码与Google表格中的验证码进行比较。是否可能(使用或不使用apps-script)?如果可能的话,我需要相应地显示下一张表格。
解决方法
如果这是您Google表单中的唯一项目,则此代码如果与工作表第1列中名为“ ListOfCodes”的任何项目匹配,则返回true。
function onFormSubmit(e) {
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('ListOfCodes')
const listofcodes=sh.getRange(1,1,sh.getLastRow()).getValues().map(function(r){return r[0];})
if(listofcodes.indexOf(e.values[1])!=-1) {
return true;
}
}
我添加了此代码以对其进行测试,并且工作正常。
function onFormSubmit(e) {
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('ListOfCodes')
const listofcodes=sh.getRange(1,sh.getLastRow()).getValues().map(function(r){return r[0];})
var idx=listofcodes.indexOf(e.values[1]);
if(idx!=-1) {
Logger.log(idx)
return true;
}
}
您如何运行它?