从上下文菜单触发Spreedsheet中的Google Apps脚本 [英] Trigger Google Apps Script in Spreedsheet from context menu

查看:38
本文介绍了从上下文菜单触发Spreedsheet中的Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Spreedsheet 中有 Google Apps脚本,该代码适用于当前选定的行.要运行它,我必须从脚本管理器中选择此脚本.是否可以将此脚本添加到上下文菜单或绑定到某些快捷方式?

I have Google Apps Script in Spreedsheet that works on currently selected row. To run it I have to select this script from script manager. Is it possible to add this script to the context menu or bind to some shourtcut ?

推荐答案

您可以使用onOpen函数创建带有按钮的菜单,该菜单将运行所需的脚本.请参见应用脚本文档.

You can create a menu with button that will run the script that you want using the onOpen function. See the Apps Script documentation.

function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Read Data",
    functionName : "readRows"
  }];
  sheet.addMenu("Script Center Menu", entries);
};

您将拥有其他类似的功能.

You would then have some other function like this.

function readRows() {

这可以执行您想要的任何功能,并且您可以有多个菜单项执行不同的功能.

This can execute any function you want, and you can have multiple menu items that do different things.

注意: onOpen 有时需要一段时间才能加载,因此请等待5秒钟.

Note: onOpen sometimes takes a while to load, so wait 5 seconds.

这篇关于从上下文菜单触发Spreedsheet中的Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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