如何从同一库生成的电子表格下拉菜单中调用库函数 [英] How to call a library function from a spreadsheet drop-down menu generated by the same library
问题描述
我创建了一个具有创建新电子表格菜单的特定功能的库(使用addMenu)。我的菜单选项应该调用我的库中的其他函数来执行其他功能。
//在带有$ b的空白电子表格上的最小部署$ b //我的库已注册(在本例中称为myLibraryName)。
函数onOpen(){
myLibraryName.setMenus(); //创建新的下拉菜单
function onEdit(event){
myLibraryName.doEvent(event); //将onEdit事件发送到我的库中的函数。
}
现在的问题是,当我选择一个菜单选项时,我有一个错误消息,如
lockquote
脚本函数 myMenuFunction 无法找到
所以我试着在我的菜单条目中添加一个前缀
menuEntries .push({name:About,functionName:myLibraryName.myMenuFunction});
但它也不起作用。
所以我要求提供关于如何创建一个可以创建与库中函数链接的菜单的库的建议。
有一个这里有个很好的例子。
在仔细查看您的问题时,您似乎试图在电子表格的不同菜单中调用相同的功能。基于我链接的错误,您可能无法执行此操作,因为您需要定义本地函数并使用它来与脚本进行交互。
I created a library that has a specific function that create new spreadsheet menus (using addMenu). My menus options should call other functions within my library to do stuff.
// Bare Minimum Deployment on a blank spreadsheet with
// my library registered (called myLibraryName for this example).
function onOpen() {
myLibraryName.setMenus(); // creating new drop-down menus
}
function onEdit(event) {
myLibraryName.doEvent(event); // sending the onEdit event to a function in my library.
}
Now the issue is that when I choose a menu option, google app script give me an error message like
Script function myMenuFunction could not be found
So I tried to add a prefix in my menu entry
menuEntries.push({name: "About", functionName: "myLibraryName.myMenuFunction"});
But It's also not working.
So I am asking for suggestions on how to create a library that can create Menus that are linked to functions within the library.
I'm not 100% sure what you're calling, but I think this is a known issue.
Looks like you need to call a function directly from the menu, not call it from the upper level.
There's a good example here.
In looking at your question closer, it seems like you're trying to call the same function across different menus in your spreadsheet. Based on the bug I linked, you probably can't do this since you need to define a local function and use that to interact with the script.
这篇关于如何从同一库生成的电子表格下拉菜单中调用库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!