在电子表格中插入新行时,我要检查电子表格中是否已经存在该数据。而且我还想为插入表中的每一行自动增加一列。
function insert_value(request, sheet)
{
var firstname = request.parameter.firstname;
var lastname = request.parameter.lastname;
var mobileno = request.parameter.mobileno;
var emailid = request.parameter.emailid;
var password = request.parameter.password;
var flag = 1;
var lr = sheet.getLastRow();
for (var i = 1; i <= lr; i++)
{
var mobileno1 = sheet.getRange(i, 2).getValue();
var emailid1 = sheet.getRange(i, 2).getValue();
if ((mobileno1 == mobileno)||(emailid1 == emailid))
{
flag = 0;
var result = "User already exists..";
}
}
//add new row with recieved parameter from client
if (flag == 1)
{
var sno=sno+1;
var lockerno=lockerno+1;
var d = new Date();
var currentTime = d.toLocaleString();
var rowData = sheet.appendRow([sno,firstname,lastname,mobileno,emailid,password,lockerno]);
var result = "Registered successful";
}