[英]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.