google-apps-script - 允许编辑者编辑某些受保护单元格的 Google Apps 脚本
问题描述
我的代码真的需要帮助。我和其他一些朋友一起做的兼职是家教。每周,我都会创建一张表格,让我的朋友根据他们辅导的人群填写列。因为有时我的一些朋友错误地填写了错误的列,所以我保护这些列并允许他们通过保护他们不应该填写的每个单元格来编辑各自的列。因为每周都这样做太乏味了,所以我想编写一个代码,这样当我运行它时,它会看到哪个编辑器正在访问工作表并保护除了他们应该编辑的单元格之外的所有其他单元格。下面是我正在处理的类似代码,但我无法正常工作。细胞,cell1 和 cell2 代表三组不同的人,它们分别使用列表 1 电子邮件进行辅导,但 cell2 由两封电子邮件组成。这些电子邮件代表向各自专栏输入数据的编辑(指导他们各自的群体)。Range、range1 和 range2 由导师需要填写的单元格组成。我对编码几乎一无所知,这是我可以根据我能找到或学到的东西来收集的。如果有人可以帮助我编辑我的代码,我真的很感激,因为我不知道该怎么做。我对编码几乎一无所知,这是我可以根据我能找到或学到的东西来收集的。如果有人可以帮助我编辑我的代码,我真的很感激,因为我不知道该怎么做。我对编码几乎一无所知,这是我可以根据我能找到或学到的东西来收集的。如果有人可以帮助我编辑我的代码,我真的很感激,因为我不知道该怎么做。
function onOpen() {
var ss = SpreadsheetApp.getActive();
var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("test 3");
var email = Session.getActiveUser().getEmail();
var cell = source.getRange("A6").getValue();
var cell1 = source.getRange("C6").getValue();
var cell2 = source.getRange("E6:E7").getValue();
var range = ss.getRange('H5:H20');
var range1 = ss.getRange('J5:J20');
var range2 = ss.getRange('L5:L20');
if (cell == email) {
// Remove protection if cell 'A6' is email@gmail.com
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
protection.remove();
}
}else {
// Protect range H5:H20 if cell 'A6' is not email@gmail.com
var protection = range.protect().setDescription('Sample protected range');
Logger.log
}
if (cell1 == email) {
// Remove protection if cell 'C6' is email1@gmail.com
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
protection.remove();
}
}else {
// Protect range H5:H20 if cell 'C6' is not email1@gmail.com
var protection = range.protect().setDescription('Sample protected range');
Logger.log
}
if (cell2 == email) {
// Remove protection if cell 'C6' is email2@gmail.com
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
protection.remove();
}
}else {
// Protect range H5:H20 if cell 'C6' is not email2@gmail.com
var protection = range.protect().setDescription('Sample protected range');
Logger.log
}
}
解决方案
推荐阅读
- sql - 每种类型如何只返回一条记录?
- c - C 中带有 OMP 的链表:内存问题
- typo3 - 升级到TYPO3 v9.5.14后出现路由异常
- sql - SQLite3 创建表意外“(”错误
- php - 如何使用 sendgrid 在 PHP 中设置样式(html 和 css)电子邮件正文以发送电子邮件?
- flutter - ScreenUtil.instance = ScreenUtil(宽度: 750, 高度: 1334, allowFontScaling: true); 为什么它给我错误?
- r - 根据 R 中的另一列创建一个新变量
- ios - 自动布局约束在运行时消失
- angularjs - AngularJs:如何使用 IFFE 声明一个应用程序和多个控制器、服务等?
- postgresql - 从旧的完整转储和/或最新的基本目录和其他获救文件恢复 PostgreSQL-9.6 数据库