javascript - 有没有办法使用谷歌脚本为某个范围设置编辑器?
问题描述
我正在尝试为工作表上的某个范围设置编辑器。我发现这个名为 getEditors() 的函数给出了某个定义范围内所有编辑器的列表。我们也可以设置编辑器吗?
解决方案
Protection类具有不同的方法,允许您修改电子表格范围的编辑器。
要设置编辑器,您可以使用方法addEditor(),要删除编辑器,请使用removeEditor。
样品:
// Protect range A1:B10, then remove all other users from the list of editors.
var ss = SpreadsheetApp.getActive();
var range = ss.getRange('A1:B10');
var protection = range.protect().setDescription('Sample protected range');
// Ensure the current user is an editor before removing others. Otherwise, if the user's edit
// permission comes from a group, the script throws an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
推荐阅读
- php - 警告:require_once():打开流失败:中没有这样的文件或目录
- python - 找不到带有 Splinter 的元素,尝试了所有方法并每次都返回空字符串
- python-3.x - 应用连接组件后如何屏蔽或裁剪图像区域
- oracle-apex - Oracle Apex 5.1.1 带有 PL/SQL 的交互式报表
- gradle - Gradlew 无法预留 3G 堆内存。属性设置为1G
- node.js - ejs文件中的相对路径
- ios - UITableView 标题部分的高度不会为自定义 UIView() 类自动调整
- html - CSS - 通过其结构而不是大量的类来样式化网站
- yii - Yii 搜索重复的结果
- c++ - qt优化轮廓文本的绘制