![](/img/trans.png)
[英]Google Script to copy specific columns from one sheet to another sheets last row onEdit
[英]onEdit specific cell copy data from one google sheets to another
在谷歌表中,我试图将一个数据从一张表复制到另一张表。
我有这段代码正在运行,但是我希望它在更改 Googlesheet1 中的单元格 E4 时运行 onEdit。 我是新手,似乎无法与我在网上找到的解决方案完全配合。
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
触发器之间进行选择onEdit
触发器就足够了,要使用它,您只需将 function ExportRange()
重命名为onEdit()
onEdit
可以为您提供有关event range
的其他信息 - 即已编辑的范围if
语句来指定该功能的 rest 只有在event range
和相应的工作表符合要求时才运行样本:
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);
}
}
请注意,此 function 只能在编辑的情况下由触发器触发。 如果您尝试手动运行它,它将给您一个错误,因为如果该功能未被编辑事件调用,则
event
(以及event.range
)将是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.