Jef*_*eff 3 google-sheets google-apps-script
我想以编程方式提取 Google Apps 项目中所有功能的列表。任何服务中似乎都没有一种方法可以轻松提取它们,除非它似乎以某种方式存储在 .this 函数中。最好的方法是什么?
我可以像上面那样理解。如果我的理解是正确的,这个答案怎么样?请将此视为多个答案之一。
在此模式中,Apps Script API 用于检索函数列表。当使用Apps Script API的projects.getContent方法时,您可以检索Google Apps Script项目中的所有函数名称。
首先,作为测试用例,您可以在Try this API进行测试。使用时,请设置脚本 IDfiles(functionSet,name)和fields。
这是 Google Apps 脚本的示例脚本。使用Apps Script API的projects.getContent方法。在使用该脚本之前,请先进行以下设置。
设置:https://www.googleapis.com/auth/script.projects.readonly到范围。myFunction()。这样,就可以检索到所有函数的列表。
脚本:function myFunction() {
var scriptId = "###"; // Please set the script ID here.
var url = "https://script.googleapis.com/v1/projects/" + scriptId + "/content?fields=files(functionSet%2Cname)";
var options = {
"method" : "get",
"headers": {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
};
var res = UrlFetchApp.fetch(url, options);
Logger.log(res.getContentText())
}
Run Code Online (Sandbox Code Playgroud)
在此模式中,this使用 。你的问题中也提到了这一点。在这种情况下,不使用任何 API。请将以下脚本复制并粘贴到脚本编辑器中,然后运行myFunction()。这样,就可以检索到所有函数的列表。
function myFunction() {
for (var key in this) {
if (typeof this[key] == "function") {
Logger.log(key)
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我误解了你的问题并且这不是你想要的方向,我很抱歉。
| 归档时间: |
|
| 查看次数: |
1392 次 |
| 最近记录: |