[英]onEdit() trigger is unable to create a new Spreadsheet
I am trying to create a custom function which copies the values of one Sheet and creates another Spreadsheet with those.我正在尝试创建一个自定义 function 复制一个工作表的值并用这些创建另一个电子表格。 The Code all in all works just fine, but I need to acces it from mobile.代码一切正常,但我需要从手机访问它。 Thats why im using the onEdit(e) trigger.这就是我使用 onEdit(e) 触发器的原因。 Using this, the script stops in the moment it should create the new sheet.使用这个,脚本在它应该创建新工作表的那一刻停止。 I checked this with a status box and every time it crashes at "Creating Sheet".我用一个状态框检查了这个,每次它在“创建工作表”时崩溃。 Is there any other way, so that I can acces my script on mobile or to fix that weird issue.有没有其他方法,以便我可以在移动设备上访问我的脚本或解决这个奇怪的问题。
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var r = s.getActiveRange();
if(s.getName() == "FlugbuchExport" && r.getColumn() == 4 && r.getRow() == 4 && r.getValue() == true){
var infoCell = s.getRange(6,3,1,3);
infoCell.setValue("");
infoCell.setValue("Process started");
var dataSheet = ss.getSheetByName("Flugbuch-GmbH");
var windenkladde = ss.getSheetByName("Windenkladde");
var dateRange = windenkladde.getRange(20,4);
var date = dateRange.getValue();
var dateString = Utilities.formatDate(date, "UTC", "dd.MM.yyyy");
var downloadLinks = ss.getSheetByName("Downloadlinks");
infoCell.setValue("Neue Tabelle wird erstellt");
var ssNewName = "LFO " + "Flugbuch - GmbH - " + dateString;
infoCell.setValue("Creating sheet");
var ssNew = SpreadsheetApp.create(ssNewName, dataSheet.getLastRow(), dataSheet.getLastColumn());
var ssNewId = ssNew.getId();
infoCell.setValue("Data got copied");
dataSheet.copyTo(SpreadsheetApp.openById(ssNewId));
var ssNewSheetDelete = ssNew.getSheets()[0];
ssNew.deleteSheet(ssNewSheetDelete);
downloadLinks.appendRow([date,ssNew.getUrl()]);
infoCell.setValue("Process finished");
r.setValue(false);
}
}
onEdit
trigger您正在使用一个简单的onEdit
触发器Simple trigger have restrictions , such as:简单的触发器有限制,例如:
They cannot access services that require authorization.他们无法访问需要授权的服务。
If you go from the script editor on View - > Executions
, you will see that the execution failed with a message like如果您在View - > Executions
上的脚本编辑器中使用 go,您将看到执行失败并显示如下消息
Exception: You do not have permission to call SpreadsheetApp.create. Required permissions: https://www.googleapis.com/auth/spreadsheets
onEdit
trigger through an installable one通过可安装的触发器替换简单的onEdit
触发器onEdit
为此,将您的 function 重命名为与onEdit
不同的名称Edit > Current project's triggers
Go on Edit > Current project's triggers
Add Trigger
点击Add Trigger
Choose which function to run
Select 您在Choose which function to run
下的功能Select event type
On edit
指定Select event type
On edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.