Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
877 views
in Technique[技术] by (71.8m points)

google apps script - Adding arguments to a function in the onOpen entries object

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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");
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...