Trigger Google Apps Script in Spreedsheet from context menu

眉间皱痕 提交于 2021-02-19 06:13:38

问题


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 ?


回答1:


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.

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



来源:https://stackoverflow.com/questions/14703413/trigger-google-apps-script-in-spreedsheet-from-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!