【问题标题】:Managing Google Protected Cells in Google Sheet在 Google 表格中管理受 Google 保护的单元格
【发布时间】:2017-05-27 19:45:57
【问题描述】:

我有一个 Google Drive 文件夹,其中包含 30 多个 Google 表格。在每张工作表中,我有 5 个以上的选项卡,每个选项卡都至少有一组受保护的单元格,或者选项卡本身。我想知道,是否可以将受保护单元格的所有这些权限作为文本输入到一个 Google 表格中,以便能够快速查看并可能管理权限。然后,我的长期目标是直接从该 Google 表格管理受保护的单元格。我一直在寻找,但没有找到任何资源让我走上正确的道路。

【问题讨论】:

    标签: google-apps-script google-sheets google-api file-permissions


    【解决方案1】:

    我写这个脚本是为了完成你想要的任务,

    要运行脚本,您需要打开一个电子表格,或者创建一个新的然后 转到工具->脚本编辑器创建它,然后复制/粘贴代码。

    更改容器文件夹 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(";"));
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 2019-07-26
      • 2015-09-26
      相关资源
      最近更新 更多