简体   繁体   English

用于在Google表格中添加数据范围的脚本

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

相关问题 用于在 Google 表格中附加数据范围的 Google App 脚本 - Google App Script to append range of data in Google Sheets 搜索Google应用脚本以迭代工作表文件夹并将一系列数据附加到合并的主工作表中 - Searching for a Google-apps-script to iterate through a folder of sheets and append a range of data to a consolidated master sheet 如何获取脚本以在 Google 表格中以正确的顺序附加数据? - How to get a script to append the data in the right order in Google Sheets? 使用脚本将数组中的数据复制到Google表格中的某个范围 - Copying data from an array into a range in Google Sheets using script Google App 脚本表 - 如何获取突出显示的范围并将数据写入其中 - Google App script sheets - How to get the highlighted range and write data to it 使用脚本Google表格将数据从一个单元格范围移动到另一个单元格 - Moving data from one range of cells to another with a script Google Sheets Google Script - 每次使用 Google Sheets 上的 Apps 脚本运行脚本时增加数据范围 - Google Script - Increment the data range every time script is run using using Apps script on Google Sheets 有没有办法在仅追加模式下使用 Google Apps 脚本将数据从 BigQuery 加载到 Google 表格? - Is there a way to load data from BigQuery to Google Sheets with Google Apps Script on append-only mode? Google Sheets Script - 将数据范围从一张表复制到另一张表 - 整个范围不复制 - Google Sheets Script - Copying data range from one sheet to another - whole range not copying 如何解析 Google Sheets 脚本中的范围 - How to parse a range in Google Sheets script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM