正在运行的Google应用脚本可以确定自己的资源ID吗? [英] Can a running Google apps script determine its own resource id?

查看:184
本文介绍了正在运行的Google应用脚本可以确定自己的资源ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Apps脚本可以确定自己的资源ID吗?如果可以的话,那么它可以发现它在哪个文件夹(父母)。

如果它只在一个文件夹中,那么它可以将该文件夹用作各种用途的默认文件夹。

如果它位于多个文件夹中,则资源ID不足以真正确定脚本的起始位置,因此推论的问题是Google应用程序脚本可以确定这个文件夹的资源ID是从哪里启动的?



好像这些将会是有用的补充,如果它还不存在于我曾遗漏的地方。

解决方案

对于电子表格,我发现这个工作:



var thisFileId = SpreadsheetApp.getActive()。getId();



var thisFile = DocsList.getFileById(thisfileId);


Can a Google Apps Script determine its own resource id? If it could, then it could discover what folders it is in (parents).

If it is only in one folder, then it could use that folder as a default folder for various purposes.

If it is in multiple folders, then the resource id is insufficient to truly identify where the script was started from, so the corollary question is can a Google apps script determine the resource id of the folder it was launched from?

Seems like these would be useful additions, maybe to Class Session, if it doesn't already exist somewhere that I have missed.

解决方案

For a Spreadsheet I found this to work:

var thisFileId = SpreadsheetApp.getActive().getId();

var thisFile = DocsList.getFileById(thisfileId);

这篇关于正在运行的Google应用脚本可以确定自己的资源ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆