【问题标题】:Error when sharing Sheet with Google Script与 Google 脚本共享工作表时出错
【发布时间】:2018-05-05 19:43:26
【问题描述】:
当使用运行 Google 脚本的按钮共享 Google 表格时,我遇到了以下问题:
- 当我以外的任何人单击按钮时,脚本将返回以下错误:
"您正在尝试编辑受保护的单元格或对象。如果您遇到这种情况,请联系电子表格所有者以取消保护""
我在工作表中有几个受保护的范围(现在已删除),但没有一个甚至靠近按钮。
我试图在一个共享用户的帐户上添加一个按钮并将脚本复制到一个新的脚本文件中(将共享用户创建/复制的脚本重新链接到共享用户创建的按钮),但没有有用。
谁知道这个问题的解决方案?
【问题讨论】:
标签:
google-apps-script
google-sheets
【解决方案1】:
仅通过删除单元格值来删除保护不起作用。 Class Protection 中有一个示例代码,它显示了在工作表范围内添加和删除保护:
// Remove all range protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
if (protection.canEdit()) {
protection.remove();
}
}