创建一个触发器,如果​​该人不是编辑者,则该触发器有效 [英] Create a trigger that works if the person is not an editor

查看:72
本文介绍了创建一个触发器,如果​​该人不是编辑者,则该触发器有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望人们在打开工作表时跳至当前日期行。但是,对于每个查看工作表的人,无论其编辑权限如何,都是如此。例如,我希望人们每天通过链接编辑工作表中的当前日期行。在这种情况下,onOpen()不起作用。该功能是否有任何替代或修改?

I want people to jump to the current date row when opening the sheet. However, this should be the case for everyone viewing the sheet and irrespective of their edit-rights. For example, I want that people edit the current date row in the sheet every day over the link. In this case, onOpen() does not work. Is there any alternative or modification to the function?

我被告知onOpen触发器,但是,如果有人仅通过带有edit链接的表单来编辑工作表,则此操作将不起作用权利。

I am informed about onOpen trigger, however, this would not work if somebody is editing the sheet only over the link with edit rights.

例如我想为所有人服务的代码:

This is e.g. the code I would like to work for everyone:

function onOpen() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getActiveSheet();
 var range = sheet.getRange("B:B");
 var values = range.getValues();  
 var day = 24*3600*1000;  
 var today = parseInt((new Date().setHours(0,0,0,0))/day);  
 var ssdate; 
 for (var i=0; i<values.length; i++) {
   try {
     ssdate = values[i][0].getTime()/day;
   }
   catch(e) {
   }
   if (ssdate && Math.floor(ssdate) == today) {
     sheet.setActiveRange(range.offset(i,0,1,1));
     break;
   }    
 }
}


推荐答案

我找到了以下选项:编辑触发器

I found the options: Edit Triggers

要通过脚本编辑器中的对话框手动创建可安装的触发器,请按照以下步骤操作:

To manually create an installable trigger through a dialog in the script editor, follow these steps:

从脚本编辑器中,选择编辑>当前项目的触发器。

From the script editor, choose Edit > Current project's triggers.

单击显示以下链接:未设置触发器。单击此处现在添加一个。

Click the link that says: No triggers set up. Click here to add one now.

在运行下,选择要触发的函数的名称。

Under Run, select the name of function you want to trigger.

在事件下,选择脚本绑定到的时间驱动或Google应用程序(例如,从电子表格)。

Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).

选择并配置所需的触发器类型创建(例如,每小时运行一个小时计时器或打开时触发)。

Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).

(可选)单击通知以配置如何以及何时通过电子邮件与您联系您的触发函数失败。

Optionally, click Notifications to configure how and when you are contacted by email if your triggered function fails.

单击保存。

Google对触发器的解释

这篇关于创建一个触发器,如果​​该人不是编辑者,则该触发器有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆