Create a trigger that works if the person is not an editor

孤街醉人 提交于 2019-12-23 03:18:13

问题


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?

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;
   }    
 }
}

回答1:


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.

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.

Click Save.

Google Explanation to Edit Triggers



来源:https://stackoverflow.com/questions/58185101/create-a-trigger-that-works-if-the-person-is-not-an-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!