问题
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