如何在谷歌应用程序脚本中获取文件ID

use*_*820 2 google-docs-api google-apps-script

我正在尝试获取我正在处理的文档的ID.目前我正在使用

var files = DriveApp.getFileById('whatever the doc Id is')
Run Code Online (Sandbox Code Playgroud)

这很好用.但是,我希望能够获得此应用程序可能正在运行的任何文档ID.我不希望用户进入代码并根据他们所处的文档切换ID.如果有人有任何想法,我很乐意听到他们,

谢谢

use*_*820 7

Geez我应该更加相信我的猜测和检查能力.

 var files = DriveApp.getFileById(DocumentApp.getActiveDocument().getId());
 files.setDescription(des);
Run Code Online (Sandbox Code Playgroud)

这有效


小智 5

文件/文件夹的 ID 也在其 url 中。打开您想要 id 的文件,您的网址栏显示:https://docs.google.com/document/d/exampleid1234qwer5678tyui/edit

该文档的 ID 为:exampleid1234qwer5678tyui