[英]onEdit specific cell copy data from one google sheets to another
In google sheets, I am trying to get one data to copy from one sheet to another.在谷歌表中,我试图将一个数据从一张表复制到另一张表。
I have this code which is working however I would like it to run onEdit when changing cell E4 in Googlesheet1.我有这段代码正在运行,但是我希望它在更改 Googlesheet1 中的单元格 E4 时运行 onEdit。 I am new at this and doesn't seem to get it to quite work with the solutions I found online.我是新手,似乎无法与我在网上找到的解决方案完全配合。
function ExportRange() {
var destination = SpreadsheetApp.openById('googlesheet1');
var destinationSheet = destination.getActiveSheet();
var destinationCell = destinationSheet.getRange("AC3");
var cellData = '=IMPORTRANGE("https://docs.google.com/spreadsheets/googlesheet2", "AE10:AE9697")';
destinationCell.setValue(cellData);
}
onEdit
trigger, depending on your requirements根据您的要求在简单且可安装的onEdit
触发器之间进行选择onEdit
trigger is sufficient, to use it you just need to rename your function ExportRange()
to onEdit()
对于大多数应用程序来说,一个简单的onEdit
触发器就足够了,要使用它,您只需将 function ExportRange()
重命名为onEdit()
onEdit
can give you among others information about the event range
- that is the range that has been edited因此,触发器onEdit
可以为您提供有关event range
的其他信息 - 即已编辑的范围if
statement to specify that the rest of the funciton shall only be run if the event range
and the corresponding sheet are as required现在您可以实现一个if
语句来指定该功能的 rest 只有在event range
和相应的工作表符合要求时才运行Sample:样本:
function onEdit(event) {
var range = event.range;
var sheet = range.getSheet();
if(range.getA1Notation() == "E4" && sheet.getName() == "Googlesheet1"){
var destination = SpreadsheetApp.openById('googlesheet1');
var destinationSheet = destination.getActiveSheet();
var destinationCell = destinationSheet.getRange("AC3");
var cellData = '=IMPORTRANGE("https://docs.google.com/spreadsheets/googlesheet2", "AE10:AE9697")';
destinationCell.setValue(cellData);
}
}
Please note that this function can only be fired by the trigger in case of an edit.请注意,此 function 只能在编辑的情况下由触发器触发。 If you try to run it manually, it will give you an error because
event
(and thusevent.range
) will be undefined if the funciton was not called by an edit event.如果您尝试手动运行它,它将给您一个错误,因为如果该功能未被编辑事件调用,则event
(以及event.range
)将是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.