简体   繁体   English

如何将范围从一个工作表复制到另一工作表的范围,然后重复复制到下一行

[英]How to copy a range from one sheet to a range in another sheet, then repeat copying to the next row down

I am looking for a google apps script to copy a range of cells in one sheet to another sheet, then when the first range values are user changed, copy the same range (new values), to the next row down from the first one. 我正在寻找一个Google Apps脚本,将一个工作表中的单元格区域复制到另一个工作表中,然后当用户更改了第一个范围值时,将相同的范围(新值)复制到从第一个开始的下一行。 Here is what i have so far: 这是我到目前为止所拥有的:

function copyToDatasheet() {

     var ss = SpreadsheetApp.getActiveSpreadsheet();
     var s1 = ss.getSheetByName('Mobile Form');
     var s2 = ss.getSheetByName('Data'); 

     s1.getRange('B2').copyTo(s2.getRange('P6'), {contentsOnly:true})
     s1.getRange('B4').copyTo(s2.getRange('Q6'), {contentsOnly:true})
     s1.getRange('B6').copyTo(s2.getRange('R6'), {contentsOnly:true})
     s1.getRange('B8').copyTo(s2.getRange('S6'), {contentsOnly:true})
     s1.getRange('B10').copyTo(s2.getRange('O6'), {contentsOnly:true})
}

All this does is copy s1 ranges to s2 ranges starting on row 6, which is how I want it to start but on the next entry I want it to move down to row 7 and so on. 这一切都是将s1范围复制到s2范围,从第6行开始,这是我希望它开始的方式,但是在下一个条目上,我希望它向下移动到第7行,依此类推。 s1 ranges are reset and new values entered, copy them to s2 in next row down Having them dynamically move down on next run. 重置s1范围并输入新值,然后将它们复制到下一行的s2中,让它们在下一次运行时动态下移。 Hope this makes sense, I do not have a ton of knowledge about apps script so explaining what some functions do would be helpful if possible. 希望这是有道理的,我对应用程序脚本不了解很多,因此,如果可能的话,解释一些功能会有所帮助。 Thanks for any assistance anyone can offer. 感谢您提供任何帮助。

This will get the same data range when there is an edit to the Sheet1. 当对Sheet1进行编辑时, 它将获得相同的数据范围。 Then all of that data will then be appended to the Sheet2. 然后,所有这些数据将被附加到Sheet2。

function getMultipleValues(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Sheet1');

  var range = sheet.getRange(2,1,4,2); //getRange(starting row, starting column, ending row, ending column)
  var data = range.getValues();
  putMultipleValues(data)
}

function putMultipleValues(data){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Sheet2');
  data.forEach(function(i){
    SpreadsheetApp.flush();
    sheet.appendRow(i)
  })
}

Don't forget to set the triggers. 不要忘记设置触发器。 In the menu => Edit => Current project's triggers. 在菜单=>编辑=>当前项目的触发器中。 在此处输入图片说明

暂无
暂无

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

相关问题 如何使用 Google Sheet Script 将数据范围从一个工作表复制到另一个工作表 - How to Copy a data range from one sheet to another sheet using Google Sheet Script 将范围从一个工作表复制到Google工作表中的另一个工作表 - Copy a range from one sheet to another in google sheet 将特定范围复制到从一个工作表到另一个工作表中的第一个空行和特定列 - Copy a specific range to from one sheet to the first empty row and specific column in another sheet Google Spreadsheets 脚本 - 如何将范围从一张纸复制到另一张纸,但不覆盖非空目标单元格 - Google Spreadsheets script - How to copy range from one sheet to another sheet, but without overwriting non-empty target cells 进行编辑后,如何将范围从一个Google表格复制到另一个表格? - How do I copy a range from one Google Sheet to another when edits are made? Google脚本:如何将范围复制并粘贴到不为空的行中的新表中 - Google Script: How to copy and paste range to a new sheet on a row that is not empty 在我将一系列数据从一张纸复制到另一张纸后获取要添加的日期戳 - Getting a date stamp to add in after i copy a range of data from one sheet to another Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet Google Script:根据值将行从一张纸复制到另一张纸 - Google Script: Copy row from one sheet to another depending on value 根据单元格值将行从一张纸复制到另一张纸 - Copy row from one sheet to another base on cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM