如何在应用程序脚本中通过菜单项传递参数 [英] How to pass parameters with menu items in apps script

查看:78
本文介绍了如何在应用程序脚本中通过菜单项传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些要从主Google工作表推送到其他工作表的信息,我想将其转换为菜单项,所以我添加了:

I have some information that I would like to push from a primary google sheet to other sheets which I need to select, I would like to turn this into a menu item so I've added:

  ui.createMenu('Push to Sheet').addItem('Select Sheet', 'myFunction').addToUi();

我有一个复杂的功能,其开头为:

I have a complicated function that starts with:

function myFunction(PARAM1,  PARAM2) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  .......

我不清楚如何使用此技术将参数传递给函数.我该如何工作?

I'm not clear How to pass parameters to the function using this technique. How can I get this working?

推荐答案

无法将参数传递给与菜单项关联的函数.不知道为什么要这么做.除非您有多个菜单项使用相同的功能,并且您试图确定选择了哪个菜单项,除非您选择了该菜单项.在这种情况下,您将需要一个包装函数,例如myFunction1(),myFunction2()等,分别链接到每个菜单项.然后在myFunction1()中调用myFunction(1).

There is no way to pass a parameter to the function associated with a menu item. Not sure why you would. Unless you have more than one menu item that uses the same function and you are trying to determine which menu item was selected. In that case you would need a wrapper function something like myFunction1(), myFunction2(), etc. linked to each menu item individually. Then within myFunction1() you call myFunction(1).

这篇关于如何在应用程序脚本中通过菜单项传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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