我在电子表格中有一个onEdit函数,我需要将其复制到另一个电子表格,其他电子表格是相同的副本,具有相同的工作表名称。它在我最后一次检查时工作得很好但是那是几天前它现在刚刚停止。
代码:
function onEdit(e){
// Logger.log("working so far 1");
// mainfile();
Logger.log("working so far 4");
// var ss=SpreadsheetApp.openById(mainssid);
var ss=SpreadsheetApp.openById("Sheet ID");
var sh=ss.getSheetByName(e.range.getSheet().getName());
var rg=sh.getRange(e.range.rowStart,e.range.columnStart);
rg.setValue(e.value);
}
function mainfile(){
Logger.log("working so far 2");
var SSID = SpreadsheetApp.getActiveSpreadsheet().getId();
var folder = DriveApp.getFileById(SSID).getParents().next().getName();
var files = DriveApp.getFoldersByName(folder).next().getFiles();
var array = [];
while (files.hasNext()) {
var file = files.next();
array.unshift(file.getName());
}
array.sort();
var mainss = array[0];
var mainssid = DriveApp.getFilesByName(mainss).next().getId();
Logger.log(mainssid);
Logger.log("working so far 3");
}
我将mainfile函数只是获取特定文件的ID,注释掉的部分就是我试图在onEdit函数中实现的部分。所以预期的结果是让我在一个电子表格上进行编辑,并在另一个电子表格上进行相同的更改,并且日志会说到目前为止数字2,3,4的Woriking,但没有出现。
当我运行mainfile函数时,它运行得很好。我也知道这可能是here的转贴,但看到他们实际上没有得到答案,它只是固定自己,我认为它可能不符合条件。
它不是其他帖子的复制品,因为我不是要发送电子邮件。我看过simple triggers guide并且我无法弄清楚这个代码有什么问题,因为它没有要求获得正常运行该功能的权限所以我认为我不需要autharisation来运行它,我知道它可以修改其他文件,因为它曾经工作,我今天有它工作,它运行超过30秒,我没有超过配额。似乎没有其他人适用。请你能解释一下我做错了什么,因为我不明白。
我还用表单ID替换了表单ID。 onEdit()代码的所有学分都是Cooper。
提前谢谢,抱歉咆哮。
简单触发器不能执行需要授权的操作。
Restrictions
Because simple triggers fire automatically, without asking the user for authorization, they are subject to several restrictions:
The script must be bound to a Google Sheets, Slides, Docs, or Forms file, or else be an add-on that extends one of those applications.
They do not run if a file is opened in read-only (view or comment) mode.
Script executions and API requests do not cause triggers to run. For example, calling Range.setValue() to edit a cell does not cause the spreadsheet's onEdit trigger to run.
They cannot access services that require authorization. For example, a simple trigger cannot send an email because the Gmail service requires authorization, but a simple trigger can translate a phrase with the Language service, which is anonymous.
They can modify the file they are bound to, but cannot access other files because that would require authorization.
They may or may not be able to determine the identity of the current user, depending on a complex set of security restrictions.
They cannot run for longer than 30 seconds.
In certain circumstances, editor add-ons run their onOpen(e) and onEdit(e) simple triggers in a no-authorization mode that presents some additional complications. For more information, see the guide to the add-on authorization lifecycle.
Simple triggers are subject to Apps Script trigger quota limits.
These restrictions do not apply to doGet(e) or doPost(e).