简体   繁体   English

onEdit 特定单元格将数据从一个谷歌表格复制到另一个

[英]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);
}
  • Chose between a simple and installable onEdit trigger, depending on your requirements根据您的要求在简单可安装onEdit触发器之间进行选择
  • For most applciaitons a simple onEdit trigger is sufficient, to use it you just need to rename your function ExportRange() to onEdit()对于大多数应用程序来说,一个简单的onEdit触发器就足够了,要使用它,您只需将 function ExportRange()重命名为onEdit()
  • Take advantage of event objetcs that give you informaiton about the event that fired the trigger利用事件对象,为您提供有关触发触发器的事件的信息
  • So, the trigger onEdit can give you among others information about the event range - that is the range that has been edited因此,触发器onEdit可以为您提供有关event range的其他信息 - 即已编辑的范围
  • Now you can implement an 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 thus event.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.

相关问题 谷歌脚本将特定列从一张纸复制到另一张纸上的最后一行 - Google Script to copy specific columns from one sheet to another sheets last row onEdit Google Sheets OnEdit脚本:从特定列复制值 - Google Sheets OnEdit script: copy value from specific columns 谷歌表格我可以使用超链接从一个单元格跳转到另一个单元格并将数据复制到另一个单元格吗 - Google sheets can I use hyperlink to jump from one cell to another and copy data to the other cell 将单元格值从一张纸复制并粘贴到另一张onEdit - copy and paste cell value from one sheet to another onEdit Google Sheets + Apps Scripts,从一个工作表复制/粘贴到另一个工作表,但粘贴到特定列 (B) 中的第一个空单元格 - Google Sheets + Apps Scripts, Copy/Paste from one sheet to another, but Paste into first empty cell in specific column (B) 将数据从一个 Google 工作表工作簿工作表复制到另一个工作簿 - Copy Data from One Google sheets Workbook Sheet to another Workbook 谷歌表格复制一个单元格并粘贴到另一个单元格 - Google Sheets Copy one Cell and paste into another Cell Google 表格应用程序脚本 - 将 function 转换为特定单元格的 onEdit - Google Sheets App Script - Convert a function to an onEdit of a specific cell Google表格可以将一个单元格更改为另一个单元格 - Google Sheets change one cell from another 如何使用谷歌表格中的脚本将图像从一个单元格复制到另一个单元格? - How can I use a script in google sheets to copy an image from one cell to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM