Javascript 使用应用程序保护范围脚本花费太多时间
某些上下文Javascript 使用应用程序保护范围脚本花费太多时间,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,某些上下文 我通过邀请翻译的谷歌电子表格管理我的网络应用的翻译 共有30张,每张代表应用程序的一部分(大应用程序) 每张图纸上有14列,1列/语言 我想做什么 由于我已经有两次遇到翻译人员错误编辑错误列的问题,我想将每个翻译人员的编辑限制为仅限于其语言的列(1个翻译人员=1个允许访问电子表格的电子邮件地址) 我是怎么做到的 手动设置是一项痛苦的任务(重复性任务),如果翻译人员发生变化,必须重新设置。所以我写了一个剧本 我如何存储权限: var ProtectionsDefinitions =
- 我通过邀请翻译的谷歌电子表格管理我的网络应用的翻译
- 共有30张,每张代表应用程序的一部分(大应用程序)李>
- 每张图纸上有14列,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
}
}
为什么不满意
- 功能
每保护一个量程需要2秒setProtection
- 我有30张纸*14列=420个范围需要保护李>
- 整个执行过程超过了google apps脚本允许的最大时间(约6分钟)
- 翻译数据已被清除
- 保留图纸的结构,脚本在脚本编辑器中可用
- 并行处理(两个问题等效答案)
- 到
- 到
- 使用连续批次库(请参阅至)