使用应用程序脚本将表单提交到电子表格时出错

cdm*_*m89 3 google-sheets google-apps-script google-forms

我创建了这个脚本,它使一个表单发布一个模糊,我希望它被提交到电子表格,但我不断得到这个错误,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;
}
}
Run Code Online (Sandbox Code Playgroud)

Sno*_*rnt 6

如果您的二维数组没有100%四边形设置并且与所选范围不匹配100%,也会发生此错误.

例如,如果你有一个数组:

[
[a,b,c,d,e,f,g],
[a,b,c,d,e,f,g],
[a,b,c,d,e,f]
]
Run Code Online (Sandbox Code Playgroud)

它会给你一个错误的说法 Exception: incorrect range width, was 7 but should be 6

当然,解决方案是用空值填充多余的单元格:

[
[a,b,c,d,e,f,g],
[a,b,c,d,e,f,g],
[a,b,c,d,e,f,''],
]
Run Code Online (Sandbox Code Playgroud)

基本上,确保它们都不比任何其他阵列长.