简体   繁体   English

onEdit() 触发器无法创建新的电子表格

[英]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);
  }

}

You are using a simple 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

Solution解决方案

  • Replace the simple onEdit trigger through an installable one通过可安装的触发器替换简单的onEdit触发器
  • For this, rename your function to something different than onEdit为此,将您的 function 重命名为与onEdit不同的名称
  • Go on Edit > Current project's triggers Go on Edit > Current project's triggers
  • Click on Add Trigger点击Add Trigger
  • Select your funciton under Choose which function to run Select 您在Choose which function to run下的功能
  • Specify Select event type On edit指定Select event type On edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 电子表格中特定工作表的 onEdit 触发器? - onEdit trigger for specific sheets in a spreadsheet? 使用onEdit触发器将值返回到Google电子表格中的单元格 - Return a value to a cell in google spreadsheet with an onEdit trigger 如何触发Google电子表格功能onEdit? - How to trigger a google spreadsheet function onEdit? onEdit可以通过编程方式创建触发器吗? - onEdit can programmatically create a trigger? 时钟触发器更新电子表格,可运行的触发器onEdit未运行 - Clock Trigger updates spreadsheet, Installable Trigger onEdit not running 如何使用 G-Suite 开发人员中心创建带有“来自电子表格”事件源的独立 onEdit(e) 触发器? - How can I create a stand-alone onEdit(e) trigger with a 'from Spreadsheet' event source using G-Suite Developer Hub? 可以在Google Spreadsheet的onEdit触发器内使用jdbc吗? - Can jdbc be used inside an onEdit trigger in a Google Spreadsheet? 当另一个脚本编辑电子表格时,执行onEdit()的问题会触发 - Problems executing onEdit() trigger when another script edit the spreadsheet IFFT 填充的 Google 电子表格日志不会触发 onEdit 脚本 - IFFT Populated Google Spreadsheet Log Does not Trigger onEdit Script 对从另一个电子表格上传的数据使用onEdit触发器 - Using onEdit trigger on data that is uploaded from another spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM