Adding arguments to a function in the onOpen entri

2020-02-04 22:17发布

Is there are a way I can add arguments to a function that will be added to the Script Center Menu on a Google Spreadsheet document? This is the normal onOpen method.

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

I was wondering if there is something similar to the following.

function onOpen() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Summary",
    functionName : "myOnOpen",
    arguments : [value: "Some value"]
  }
  ];
  sheet.addMenu("Script Center Menu", entries);
};

Thanks!

1条回答
在下西门庆
2楼-- · 2020-02-04 22:48

I don't think that is possible exactly as you have written, but you can do it in the following way:

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

function myParameterisedOpen() {
  myOnOpen("Some value");
};
查看更多
登录 后发表回答