我有一个Google工作表,其中有一个特定的工作表,我想防止它根据日期和时间进行编辑。我看到了针对特定单元格执行此操作的代码,但我想针对整个工作表执行此操作,并保留编辑者列表(只是防止公共编辑)。
我尝试使用在这里找到的一些代码:Locking cells in Google Sheets at a specific time,但不确定如何针对我的用例修改此代码。
编辑:
仔细查看此页面: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 throws an exception upon removing the group.
var me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
但是,如何声明特定的工作表名称?电子表格中有多个标签。什么是getActive要拉?
答案 0 :(得分:0)
但是,如何声明特定的工作表名称?电子表格中有多个标签。什么是getActive要拉?
SpreadsheetApp.getActive()
返回一个Spreadsheet对象,该对象代表保存该脚本的代码的电子表格,该脚本是一个有界脚本,或者将一个函数调用为包含脚本的插件的电子表格。
使用getSheetByName(name)来获取工作表对象的名称。