如何从onOpen()
函数代码动态定义电子表格的自定义函数?
- 写个代码...
function onOpen() {
//var s = SoapService.wsdl("http://example.com/service.wsdl", "serv");
//var funcs = s.getServerFunctions();
var funcs = { "pow2": "function (v) { return v*v};" }
for(var f in funcs)
{
this[f] = eval(funcs[f]) // define server functions as custom google-script functions for spreadsheet using this[function_name] = eval(function_code)
}
}
- 尝试
=pow2()
从任何单元格调用(“pow2”是函数名) - 得到一个错误“#NAME” - 未定义的函数