UI服务错误:请先选择活动工作表



我正试图从此页复制代码。当我部署为web应用程序时,它会显示带有输入框和提交按钮的用户界面。然而,当我点击提交时,它会弹出这个错误消息:"请先选择一个活动的工作表"。当我在电子表格中打开UI时,我得到了同样的错误。而不是使用openById我把它改为getActive。getSheetByName,它从电子表格中工作。然而,回到web应用程序,新的错误信息现在是"不能调用getSheetByName of null。"

谁能建议为什么我得到"请选择一个活动的工作表第一"错误,我需要做什么不同?

这是我复制的代码,我所做的唯一改变是把我的SS键放在两个适当的地方。

function doGet(e) {
  var doc = SpreadsheetApp.openById("yyyy"); //I've got my SS key here
  var app = UiApp.createApplication().setTitle('New app');
  // Create a grid with 3 text boxes and corresponding labels
  var grid = app.createGrid(3, 2);
  grid.setWidget(0, 0, app.createLabel('Name:'));
  // Text entered in the text box is passed in to userName
  // The setName method will make those widgets available by
  // the given name to the server handlers later
  grid.setWidget(0, 1, app.createTextBox().setName('userName'));
  grid.setWidget(1, 0, app.createLabel('Age:'));
  grid.setWidget(1, 1, app.createTextBox().setName('age'));
  // Text entered in the text box is passed in to age    
  grid.setWidget(2, 0, app.createLabel('City'));
  grid.setWidget(2, 1, app.createTextBox().setName('city'));
  // Text entered in the text box is passed in to city.
  // Create a vertical panel..
  var panel = app.createVerticalPanel();
  // ...and add the grid to the panel
  panel.add(grid);
  // Create a button and click handler; pass in the grid object as a callback element     and the handler as a click handler
  // Identify the function b as the server click handler
  var button = app.createButton('submit');
  var handler = app.createServerHandler('b');
  handler.addCallbackElement(grid);
  button.addClickHandler(handler);
  // Add the button to the panel and the panel to the application, then display the     application app
  panel.add(button);
  app.add(panel);
  return app;

}
// Function that records the values in a Spreadsheet
function b(e) {
  var doc = SpreadsheetApp.openById("yyyy"); //I've got my SS key here
  var lastRow = doc.getLastRow(); // Determine the last row in the Spreadsheet that     contains any values
  var cell = doc.getRange('a1').offset(lastRow, 0); // determine the next free cell in     column A
  // You can access e.parameter.userName because you used setName('userName') above and
  // also added the grid containing those widgets as a callback element to the server
  // handler.
  cell.setValue(e.parameter.userName); // Set the value of the cell to userName
  cell.offset(0, 1).setValue(e.parameter.age); // Set the value of the adjacent cell to     age
  cell.offset(0, 2).setValue(e.parameter.city); // set the value of the next cell to     city
  // Clean up - get the UiInstance object, close it, and return
  var app = UiApp.getActiveApplication();
  app.close();
  // The following line is REQUIRED for the widget to actually close.
  return app;
}

谢谢!

您正在打开电子表格,并且应该在电子表格中打开工作表

sheet = doc。getSheetByName("表名称")

在文档

相关内容

  • 没有找到相关文章

最新更新