到目前为止,我已经从这个网站找到了以下内容。
这会创建一个相当大的框,但遗憾的是只询问(并返回)一个值 - 名称。
我有没有办法添加多个问题(例如年龄,出生日期)并将回复返回到同一个弹出框中的相应单元格?
换句话说,我想要弹出一个框,用户可以为三个问题中的每一个输入文字,然后按下即可提交回复。< / p>
function getInputFromNameBox() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Create the user interface
var app = UiApp.createApplication();
//Create one textboxs
var tBox1 = app.createTextBox().setName('tBox1').setId('tBox1');
//Create the OK button and a handler to respond to when OK is clicked.
var okHandler = app.createServerHandler('respondToOK');
var btnOK = app.createButton('OK', okHandler);
//I find grids very handy for arranging labels and widgets like textboxes neatly
var myGrid = app.createGrid(2, 2).setId('myGrid')
.setText(0, 0, 'Your Name')
.setWidget(0, 1, tBox1)
.setWidget(1, 1, btnOK);
/*The OK button's handler needs a callback element otherwise it can't read the user's input.
You could add multiple callback elements to each of the textboxes but that's just extra code.
As all the textboxes are added to myGrid then just one callback to that will work fine.
*/
okHandler.addCallbackElement(myGrid);
app.add(myGrid);
ss.show(app);
}
function respondToOK(e) {
var app = UiApp.getActiveApplication();
var result = e.parameter.tBox1;
//Enter the result in the cell C5
var ss = SpreadsheetApp.getActiveSpreadsheet();
var cellAddress = ss.getActiveCell().getA1Notation();
ss.getActiveSheet().getRange("rangeUserName").setValue(result); //Change to cell you want populated (you can create copies of this row to have multiple submissions of the value.
//Close the user interface
return app.close();
}