我写这个脚本是为了完成你想要的任务,
要运行脚本,您需要打开一个电子表格,或者创建一个新的然后
转到工具->脚本编辑器创建它,然后复制/粘贴代码。
更改容器文件夹 ID 的“#########################”,以确定您的文件夹的 ID,您可以打开文件夹,然后复制与 ID 对应的 URL 部分
https://drive.google.com/drive/folders/#########################
添加菜单后,需要刷新才能看到。
使用:点击Custom Utilities->Get permisions list Here,然后它将创建“sheet #”,其中包含所有信息
代码如下:
function onOpen(){
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Utilities').addItem('Get permisions list Here','testfunction').addToUi();
}
function testfunction() {
//Add a new sheet in the current Spreadsheet
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet().activate();
activeSheet.appendRow(['FileName','ID','Protection Description','Range','Type','Users']);
activeSheet.getRange("A1:F1").setFontWeight('bold');
//get all the Google Spreadsheet's files
var files = DriveApp.getFolderById("#########################").getFilesByType(MimeType.GOOGLE_SHEETS);
while (files.hasNext()) {
var file = files.next();
var ss = SpreadsheetApp.openById(file.getId());
//get the permisions in the current file, and print the data to the previous created sheet
var protectionsRange = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protectionsRange.length; i++) {
var protection = protectionsRange[i];
activeSheet.appendRow([file.getName(),file.getId(),protection.getDescription(),protection.getRange().getA1Notation(),protection.getProtectionType(),protection.getEditors().join(";")]);
//Logger.log(file.getName() + " | " + file.getId() + " \n| " + protection.getDescription() + " | " + protection.getRange().getA1Notation() + " | " + protection.getProtectionType() + " | " + protection.getEditors().join(";"));
}
var protectionsSheet = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protectionsSheet.length; i++) {
var protection = protectionsSheet[i];
activeSheet.appendRow([file.getName(),file.getId(),protection.getDescription(),protection.getRange().getA1Notation(),protection.getProtectionType(),protection.getEditors().join(";")]);
//Logger.log(file.getName() + " | " + file.getId() + " \n| " + protection.getDescription() + " | " + protection.getRange().getA1Notation() + " | " + protection.getProtectionType() + " | " + protection.getEditors().join(";"));
}
}
}