【问题标题】:Lock Google Sheet tab based on date+time根据日期+时间锁定 Google 表格标签
【发布时间】:2019-05-25 21:45:46
【问题描述】:

我有一个 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 要拉什么?

【问题讨论】:

标签: google-apps-script google-sheets


【解决方案1】:

但是,如何声明特定的工作表名称?我的电子表格中有多个选项卡。 getActive 要拉什么?

SpreadsheetApp.getActive() 返回一个电子表格对象,该对象代表保存代码的电子表格,如果脚本是有界脚本或调用函数的电子表格,则保存脚本的插件。

使用 getSheetByName(name) 通过名称获取 Sheet 对象。

【讨论】:

  • 谢谢!我能够修改代码并获得特定工作表的工作结果。
猜你喜欢
  • 2013-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-09
  • 2017-09-14
  • 1970-01-01
  • 1970-01-01
  • 2015-10-15
相关资源
最近更新 更多