【发布时间】:2013-08-29 18:11:33
【问题描述】:
我已经创建了这个脚本,它制作了一个表单来发布一个简介,我希望它被提交到一个电子表格,但是我一直收到这个错误Exception: incorrect range width, was 3 but should be 5不管我改变了 getRange 中的行数这个数字错误总是一样的。有什么方法可以更新我不知道的代码吗?我每次更改代码时都会部署代码。
function doGet() {
var app = UiApp.createApplication().setTitle('Form for news update');
//panel for form
var panel = app.createVerticalPanel().setId('panel');
//elements for the form
var postTitle = app.createLabel('Title');
var title = app.createTextBox().setId('title');
var postLabel = app.createLabel('new post:');
var post = app.createTextArea().setId('post');
var btn = app.createButton('Submit');
//handler to execute posting by click the button
var handler = app.createServerClickHandler('Submit');
handler.addCallbackElement(panel);
//add this handler to the button
btn.addClickHandler(handler);
//add the elements to the panel
panel.add(postTitle)
.add(title)
.add(postLabel)
.add(post)
.add(btn);
//add the panel to the app
app.add(panel);
return app;
}
function Submit(e){
//get the app and send it to the spreadsheet
var app = UiApp.getActiveApplication();
try{
//get the post
var postTitle = e.parameter.postTitle;
var title = e.parameter.title;
var post = e.parameter.post;
//put the info into a spreadsheet
var ss = SpreadsheetApp.openById('KEY IN HERE REMOVED FOR PRIVACY');
var sheet = ss.getSheets()[0];
sheet.getRange(sheet.getLastRow()+1, 1).setValues([[ title, post]]);
}catch(e){
app.add(app.createLabel('Error occured:'+e));
return app;
}
}
【问题讨论】:
标签: google-apps-script google-sheets google-forms