我部署了一个web应用程序,当电子表格打开时,它可以调用该函数来创建一个新菜单。
下面是我写的部分
function onOpen(){
var url = "https://script.google.com/a/slt.org.au/macros/s/AKfycby2pFGHc3qWaxnD4WGTLMEAPMUocohzH_-OsUPxwqi8kmWfRZs8/exec";
var currentSpreadsheet = SpreadsheetApp.getActive().getId();
var requestAction = "onOpen";
UrlFetchApp.fetch(url+"?requestAction="+requestAction);
}
在我的网络应用中,我写道
function onOpen(currentSpreadsheet) {
//Adds custom menu
SpreadsheetApp.openById(currentSpreadsheet);
var menu = [{name: "Add row", functionName: "addRow"},
{name: "Generate Invoice", functionName: "generateInvoice"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("Custom", menu);
}
我也试过了
function onOpen(currentSpreadsheet) {
//Adds custom menu
var menu = [{name: "Add row", functionName: "addRow"},
{name: "Generate Invoice", functionName: "generateInvoice"}];
SpreadsheetApp.openById(currentSpreadsheet).addMenu("Custom", menu);
}
仍然不工作。这意味着addMenu只能在独立脚本或内置脚本中使用吗?但不是在谷歌的网络应用中?
当我尝试使用addMenu()时,所有错误都会发生。