【问题标题】:Google spreadsheet - Error when Remove range protectionGoogle 电子表格 - 删除范围保护时出错
【发布时间】:2015-02-28 05:08:32
【问题描述】:

这是我的脚本,但由于某种奇怪的原因我无法让它工作??!!!使我抓狂。

function removeThenSetProtection() {
  // Remove all range protections in the spreadsheet that the user has
  //permission to edit.
  var ss = SpreadsheetApp.getActive();
  var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);

  for (var i = 0; i < protections.length; i++) {
    var protection = protections[i];
    if (protection.canEdit()) {
      protection.remove();
    }
  }
}

【问题讨论】:

  • 代码对我有用。我手动设置了一个受保护的范围,运行了你的代码,它删除了保护。我们需要更多信息。谁在运行脚本?不是你的用户?如果是这样,他们的权限是什么?此外,使用Logger.log('Variable Name: ' + variableName) 语句,然后查看日志。或者使用调试器逐行执行您的代码。 Troubleshooting - Breakpoints
  • 代码运行时电子表格是否真的打开了?您要操作的工作表是活动工作表吗?

标签: javascript google-apps-script google-sheets protected named-ranges


【解决方案1】:

变化:

var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);

收件人:

var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);

这样,您就可以放心,您将获得对所有受保护内容的引用,并且不会发生未来的冲突。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    相关资源
    最近更新 更多