I want to create a custom function i.e. myrange.ckeck_if_included(row,col,numrow,numcol) that returns a boolean that says me if the range given in input is included into myrange. Is it possible to create this function in class range? And how to refer my function to myrange? Thanks franko
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can always use a proxy object to do this. Here's a general proxy-making utility:
function proxy(obj) {
var x = {};
Object.keys(obj).map(function(k) { x[k] =
function() { return obj[k].apply(obj, [].slice.call(arguments, 0)); }})
return x;
}
In your case you could then do
r=proxy(SpreadsheetApp.openById("...").getSheetByName("Sheet1").getActiveRange());
r.myFunction=function () { ... }
And more generally you can even replace top-level objects with proxies:
GmailApp = proxy(GmailApp);
GmailApp.myFunction = ...
回答2:
So you want to extend an Object/Class of the Google-Services? This does not work, you get an exception "Object does not allow properties to be added or changed" if you try like this:
r=SpreadsheetApp.openById("...").getSheetByName("Sheet1").getActiveRange();
r.myFunction=function () { ... }