[英]Script to append range of data in Google Sheets
I have a script that will copy and send a range of data to another sheet. 我有一个脚本,可以将一系列数据复制并发送到另一张纸上。 I want to add another part to the script, that will do the same function but append the data to a new row.
我想在脚本中添加另一部分,该部分将执行相同的功能,但会将数据附加到新行中。
function saveToRecords() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('Report!L1:AC1');
source.copyTo(ss.getRange('Records!A3:R3'), {contentsOnly: true});
}
I have this script attached to a button in Google Sheets. 我将此脚本附加到了Google表格中的按钮上。 The data is sent form
Report!
数据从
Report!
发送Report!
to Records!
Records!
. 。 The
Records!
Records!
sheet will save this data. 工作表将保存此数据。 So each time I click the button I would like the data to be sent to a new row.
因此,每次单击按钮时,我希望将数据发送到新行。
I know there is an easy way to do this! 我知道有一个简单的方法可以做到这一点! I have been stumped.
我已经难过了。 Thanks for your help.
谢谢你的帮助。
yes, there is. 就在这里。 You can use getLastRow() .
您可以使用getLastRow() 。
So your code would look like this: 因此,您的代码如下所示:
function appendToRecords() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var reportSheet = ss.getSheetByName("Report");
var recordsSheet = ss.getSheetByName("Records")
var reportData = reportSheet.getRange("L1:AC1")
.getValues();
var lastRow = recordsSheet.getLastRow();
//copy data
recordsSheet.getRange(lastRow + 1, 12, 1, 18)
.setValues(reportData);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.