如何申请表格保护?

时间:2017-11-03 14:03:24

标签: google-apps-script

有关Excel样式的工作表保护的文档有点不清楚。 (或者,我可能只是没有正确阅读。)

我通过将其放在具有定义编辑器和阅读器的访问控制的目录中来保护电子表格。我想锁定此电子表格中的工作表,以便没有人可以编辑它,但是对文档其余部分具有编辑权限的任何人都可以删除锁定。

当我应用保护时,似乎我无法移除自己,所以我总是可以编辑工作表。当我通过脚本尝试该示例并删除me位时,我仍然可以编辑该表。如果我通过作为服务帐户运行的脚本添加此锁,我可以锁定工作表,以便其他人无法编辑它,但是,没有人可以删除锁。

以下是documentation page上第三个示例的简单修改版本,似乎有效。

function myFunction() {
  // Protect the active sheet, then remove all other users from the list of editors.
  var sheet = SpreadsheetApp.getActiveSheet();
  var protection = sheet.protect().setDescription('Test Protection');

  // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
  // permission comes from a group, the script will throw an exception upon removing the group.
  var me = Session.getEffectiveUser();
  //protection.addEditor(me);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }
}

我可能会设置一个菜单项来运行触发器作为解锁标签的服务帐户,但这看起来有点苦差事,特别是考虑到触发器的速度。

有没有人有更好的方法呢?

0 个答案:

没有答案
相关问题