某些背景
我想做什么
由于我已经有两次翻译错误地编辑错误列的问题,我想设置protected columns将每个翻译的版本限制为他的语言列(1个翻译者= 1个电子邮件地址授予访问权限)到电子表格)。
我是怎么做的
手动设置是一项痛苦(重复性任务),如果翻译人员改变,必须再次进行。所以我为它写了一个脚本。
我如何存储权限:
var ProtectionsDefinitions = [{
langHeader: "en",
emails: ["toto@gmail.com"]
},{
langHeader: "fr",
emails: ["toto@gmail.com"]
}
...]
伪代码:
For every sheet:
For every language:
Protect the column whose header match the langHeader
执行实际工作的函数的真实代码:
function setProtection(range, rangeDesc, emails) {
// range = class range
// rangeDesc = string (description for protected range)
// emails = [toto@yopmail.com, tata@yopmail.com]
var protection = range.protect(); // Creates an object that can protect the range from being edited except by users who have permission.
// Until the script actually changes the list of editors for the range
// the permissions mirror those of the spreadsheet itself, which effectively means that the range remains unprotected.
protection.removeEditors(protection.getEditors()); // this takes more than 1s !
protection.setDomainEdit(true); // all users in the domain that owns the spreadsheet have permission to edit the protected range
protection.setDescription(rangeDesc);
if(emails.length > 0){
// this takes more than 1s !!
range.getSheet().getParent().addEditors(emails); // give the users permission to edit the spreadsheet itself, required for protection.addEditors()
protection.addEditors(emails); // give the users permission to edit the protected range
}
}
为什么不满意
setProtection
每个范围需要2秒才能保护由于日志工具的原因,我追踪了需要花费很多时间的行,请参阅函数中的注释。
我想知道我是否可以采取行动使其发挥作用。
示例电子表格
答案 0 :(得分:1)
您可以申请Early Access Program,或者通过单个脚本调用处理所有工作表/列,然后拆分作业。
解决方案的想法:
相关Q& A