你好,我是谷歌应用程序脚本的新手,我想比较一下我在文本框中输入的值与 excel 表中的值。我的 excel 表的值是正确显示的,并且文本框是正确创建的(两个是因为 excel 表中有两个条目)。我要验证这一点:如果我在文本框中输入的内容大于 excel 表的值,则错误,否则没关系。我想使用提交按钮。我看到了一个带有验证电子邮件功能的示例,但我无法将其转换为我的示例。
当我调试函数validateStock(e)时,我得到参数“未定义。请帮助我。
function doGet() {
var user = Session.getUser().getUserLoginId();
var excel = SpreadsheetApp.openById("0Alg06LrHGRkddDJyMUh5bGRsZnhKQkpqYjBCN0d0X2c");
var raw = excel.getSheets()[0];
var app = UiApp.createApplication();
var stockLabel = app.createLabel('Introduza a Quantidade de Stock pretendida');
var inputBox = app.createTextBox().setId('stockBox').setName('myStock');
var submitButton = app.createButton('Validate');
var infoLabel = app.createLabel('Stock é Valido').setVisible(false).setId('info');
var panel = app.createVerticalPanel();
var list = raw.getRange("A1:A2").getValues();
for( var i = 0; i < list.length; i++)
{
//if (list[i] == user)
var cliente = raw.getSheetValues(i+1,2,1,1);
app.add(app.createLabel("Stock: "+ list[i]));
app.add(app.createTextBox());
//raw.getSheetValues(startRow, startColumn, numRows, numColumns)
}
panel.add(stockLabel)
.add(inputBox)
.add(infoLabel)
.add(submitButton);
//Add the panel to the application
//Create Click handlet and add to the submit button
var handler = app.createServerClickHandler('validateStock');
handler.addCallbackElement(panel);
submitButton.addClickHandler(handler);
panel.add(stockLabel).add(inputBox).add(submitButton);
app.add(panel);
return app;
}
//Function to validate stock and display the response
function validateStock(e){
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
var excel = SpreadsheetApp.openById("0Alg06LrHGRkddDJyMUh5bGRsZnhKQkpqYjBCN0d0X2c");
var raw = excel.getSheets()[0];
var app = UiApp.getActiveApplication();
var list = raw.getRange("A1:A2").getValues();
stock = e.parameter.myStock;
Logger.log(stock);
if(emailPattern.test(stock) == false)
app.getElementById('info').setText("Invalid Email Address").setStyleAttribute("color", "#F00").setVisible(true);
else
app.getElementById('info').setText("Valid Email Address").setStyleAttribute('color', '#339900').setVisible(true);
return app;
}
else
app.getElementById('info').setText("Valid Email Address").setStyleAttribute('color', '#339900').setVisible(true);
return app;
}