google-apps-script - 基于单元格值的 Google 表格保护
问题描述
我在一个谷歌工作表文件中有 30 个标签,它们都有相同的结构但不同的数据
我想要一个基于值锁定(保护)整个工作表的脚本
该值被定义为范围,如果该值是(已审核),我想锁定选项卡
- 单元格位置:A5
- 单元格值:“已审核”
解决方案
function protectAudited() {
var ss=SpreadsheetApp.getActive();
var shts=ss.getSheets();
shts.forEach(function(sh) {
if(sh.getRange('A5').getValue()=='audited') {
sh.protect();
}
});
}
或许是这样的:
function protectAudited() {
var ss=SpreadsheetApp.getActive();
var shts=ss.getSheets();
shts.forEach(function(sh) {
if(sh.getRange('A5').getValue()=='Audited') {
sh.protect();
}else {
var protection=sh.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
if(protection && protection.canEdit()) {
protection.remove();
}
}
});
}
推荐阅读
- python - 如何让 python 程序(应该从 csv finl 中寻找变量)通过 PHP 运行并返回相应的变量?
- excel - 将数据表写入 Excel 文件
- powershell - PowerShell icacls - 如何赋予管理员完全权限,并从非管理员用户手中夺走所有权限?
- python - Python:TypeError:需要一个整数(获取类型 sqlite3.Cursor)
- javascript - 我们可以使用 GitLab 作为 AWS CDK 管道的源代码主机吗?
- mongodb - 有没有办法只在 mongoDB 中获取最新版本的文档
- python - 将日期与时间分开
- sql - 如何根据前一行中十进制值的比较来唯一标识 TSQL 中的特定行?
- machine-learning - sklearn 管道有没有办法在网格搜索期间进行有步骤和无步骤的训练?我可以删除步骤,但如何将其传递给 GridSearchCV?
- pytest - 我们如何验证 DAG 对象中是否没有循环