【问题标题】:How to get Spreadsheeets/Documents owned by a particular user using google apps script?如何使用谷歌应用程序脚本获取特定用户拥有的电子表格/文档?
【发布时间】:2020-12-16 06:12:58
【问题描述】:
如果有人离开公司,要将他们拥有的所有文件(电子表格、文档、站点、幻灯片等)转移给其他人,是否有任何方法或功能可以使用应用程序脚本列出文件?
例如,如果我尝试列出电子邮件“xyz@google.com”的人拥有的所有电子表格,可能类似于 SpreadsheetApp.getSheetsOwnedBy("xyz@google.com")。我试图找到这样的东西,但找不到任何东西。如果您有想法,任何人都可以分享您的知识。
提前致谢!!!
【问题讨论】:
标签:
google-apps-script
google-sheets
google-docs
【解决方案1】:
您需要成为管理员才能执行此操作。
有一个很好的post 向您详细介绍了如何在 Apps 脚本中执行传输。
【解决方案2】:
我发现下面这段代码可以满足我的要求,我把这段代码留在这里以防万一有人有类似的要求。
`
function transferOwnership() {
var count = 0; //to keep track of total no. of files
var files = DriveApp.searchFiles('"me" in owners'); //can give emailAddres in place of "me"
// var files = DriveApp.searchFiles('title contains "untitled"'); //gives list of files containing the files that incluede "untitled" in file title
while (files.hasNext()) {
var file = files.next();
count++;
Logger.log(file.getName());
Logger.log(file.getMimeType()); //to know under which mime type category the file falls under
//file.setOwner("xyz@google.com"); //automatically original owner becomes editor
//file.addEditor("xyz@google.com");
}
Logger.log("total count: " + count);
}`
有人在这里发布了类似的帖子,非常有用:
Looping through multiple google spreadsheets with google scripts