当我复制电子表格脚本/触发器不起作用 [英] When i copy a spreadsheet script/triggers don't work

查看:174
本文介绍了当我复制电子表格脚本/触发器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于名为 fillvalues()的函数并带有 onEdit()触发器的电子表格,并且它工作正常。

我需要制作这个电子表格的多个副本,因为它用于制作工作报告,但是当我制作副本时,脚本不起作用,因为触发器处于非活动状态或需要授权才能运行。



如何克服这一点,以便在新电子表格中复制触发器功能并在电子表格打开时询问权限? / p>

解决方案

每位用户必须为其副本授权并创建触发器。你可以编写一个脚本,用它们来完成它们的功能,它们可以从菜单项或表单中的按钮/绘图/图像运行。



代码非常简单,就像这样(用你的函数名称替换'myFunction'):

pre $ function $ createOnEditTrigger {
var trigger = ScriptApp.newTrigger(myFunction)。forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())。onEdit()。create();
}


I've created a spreadsheet with a onEdit() trigger based in a function called fillvalues() and it works fine.

I need to make several copies of this spreadsheet because it is used to make work reports, but when I make a copy the script doesn't work because the triggers are inactive or it needs authorization to run.

How can I overcome this to copy the trigger function with the new spreadsheet and to ask permission when the spreadsheet open?

解决方案

Each user will have to authorize and create the triggers for their copy. You can write a script that will do that for them in a function that they would run from a menu item or from a button/drawing/image in the sheet.

The code is really straightforward and goes like this (replace 'myFunction' with your function name) :

function createOnEditTrigger(){
  var trigger = ScriptApp.newTrigger("myFunction").forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()).onEdit().create();
}

这篇关于当我复制电子表格脚本/触发器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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