应用脚本电子表格错误 [英] App Scripts spreadsheet error

查看:175
本文介绍了应用脚本电子表格错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在部署到Google App脚本时看到意外错误的原因... doPost中有某些内容吗?运行函数不会产生任何错误。

 函数doGet(){
var app = UiApp.createApplication();
var form = app.createFormPanel();
var flow = app.createFlowPanel();
flow.add(app.createTextBox()。setName(textBox));
flow.add(app.createListBox().setName(listBox)。addItem(option 1)。addItem(option 2));
flow.add(app.createSubmitButton(Submit));
form.add(flow);
app.add(form);
返回应用程序;
}

函数doPost(eventInfo){

var app = UiApp.getActiveApplication();
var ss = SpreadsheetApp.getActiveSpreadsheet();

ss.getRange(A1:A1);
ss.getActiveRange()。setValue(hello);

返回应用;


解决方案

SpreadsheetApp.getActiveSpreadsheet()仅适用于Spreadsheet容器绑定脚本。否则,您需要使用 SpreadsheetApp.openById 并指定要获取的电子表格键。



当您运行函数你只是在运行doGet?如果您在下拉列表中选择doPost并运行它,如果这不是电子表格绑定脚本,您应该会看到一个错误。


Does anyone see a reason for an "Unexpected error" when deployed to Google App Scripts...something in doPost? Running the function produces no errors.

function doGet() { 
  var app = UiApp.createApplication(); 
  var form = app.createFormPanel(); 
  var flow = app.createFlowPanel(); 
  flow.add(app.createTextBox().setName("textBox")); 
  flow.add(app.createListBox().setName("listBox").addItem("option 1").addItem("option 2")); 
  flow.add(app.createSubmitButton("Submit")); 
  form.add(flow); 
  app.add(form); 
  return app; 
} 

function doPost(eventInfo) { 

  var app = UiApp.getActiveApplication();
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  ss.getRange("A1:A1");
  ss.getActiveRange().setValue("hello");  

  return app; 
}

解决方案

SpreadsheetApp.getActiveSpreadsheet() only works in Spreadsheet container bound scripts. Otherwise you need to use SpreadsheetApp.openById and specify the spreadsheet key to get.

When you "run the function" are you just running the doGet? If you select doPost in the dropdown and run it, you should see an error if this is not a Spreadsheet bound script.

这篇关于应用脚本电子表格错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆