【发布时间】:2016-12-02 03:03:27
【问题描述】:
我正在尝试通过 Google 脚本锁定工作表。我想将此脚本锁定给所有用户。 我正在使用我在文档中找到的内容:https://developers.google.com/apps-script/reference/spreadsheet/protection
// 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 will throw an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
问题是应该锁定工作表的脚本是由应该看到工作表被锁定的用户运行的。
我的问题是:如何使用 Google 脚本为当前用户锁定工作表?
【问题讨论】:
标签: google-apps-script google-sheets