简体   繁体   English

修改代码 - 将某些行/列从一个电子表格复制到另一个 - Google Apps Script / Google Sheets

[英]Modify Code - Copy Certain Rows/Columns From one Spreadsheet to Another - Google Apps Script / Google Sheets

I would like to incorporate the action the SORT QUERY is doing (above .getRange line of code) in this script.我想在此脚本中合并 SORT QUERY 正在执行的操作(在 .getRange 代码行上方)。 So instead of copying A2:FI would get Column B, C, D, E copied from ONLINESendNewSkusToGID to RECTOONLINE.因此,不是复制 A2:FI,而是将 B、C、D、E 列从 ONLINESendNewSkusToGID 复制到 RECTOONLINE。

function CopyNewOnlineSkusFromCDSToGID() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('ONLINESendNewSkusToGID'), true);

  //=SORT(QUERY(JIRA JQL QUERY!A2:F,"SELECT B, C, D, E",0))
  spreadsheet.getRange('A2:F').activate();

  var target = SpreadsheetApp.openById("");
  var source_sheet = spreadsheet.getSheetByName("ONLINESendNewSkusToGID");
  var target_sheet = target.getSheetByName("RECTOONLINE");

  var source_range = source_sheet.getActiveRange();
  var last_row = target_sheet.getLastRow();
  var values = source_range.getValues();
  target_sheet.getRange(last_row + 1, 1, values.length, values[0].length).setValues(values);
  spreadsheet.getRange('A2').activate();
}

Thanks In Advance提前致谢

Solution解决方案

Here is the code snippet that copies the columns B to E from one sheet to other.这是将 B 列到 E 从一张工作表复制到另一张工作表的代码片段。 Let me know if this is what you meant to achieve with your question.让我知道这是否是您要通过问题实现的目标。

 function CopyNewOnlineSkusFromCDSToGID() { // get spreadsheet var ss = SpreadsheetApp.getActiveSpreadsheet(); // get the two desired sheets var online = ss.getSheetByName("ONLINESendNewSkusToGID"); var rect = ss.getSheetByName("RECTOONLINE"); // get the values of the sheet we want to copy var values = online.getRange('B:E').getValues(); // set the values where we want to paste rect.getRange('B:E').setValues(values); }

For more info regarding how to get and set values check out here and here respectively.有关如何获取和设置值的更多信息,请分别查看此处此处 I hope this has helped you, let me know if you need anything else or if you did not understood something.我希望这对您有所帮助,如果您需要其他任何东西或者您不明白什么,请告诉我。

暂无
暂无

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

相关问题 如何使用带有事件的谷歌应用脚本将单行中的特定列从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy specific columns from a single row from one google spreadsheet to another google spreadsheet using google apps script with an event? 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? 如何使用Google Apps脚本将特定的行从3个Google电子表格复制到另一个电子表格 - How to copy specific rows from 3 google spreadsheet to another spreadsheet using google apps script 修改代码 - 在编辑中选择某些列。 Google Apps 脚本/Google 表格 - Modify Code - Select Certain Columns onEdit. Google Apps Script / Google Sheets 修改代码 - 将范围复制到另一个电子表格 Google 表格 - Modify Code - Copy Range to another Spreadsheet Google Sheets Google Apps 脚本,将一个电子表格复制到另一个带格式的电子表格 - Google Apps Script, copy one spreadsheet to another spreadsheet with formatting CopyTo:如何使用Google Apps脚本将数据从一个Google电子表格推入/复制单元格到另一个Google电子表格? - CopyTo: How to push data/copy a cell from one google spreadsheet to another google spreadsheet using google apps script? 在 Google Apps 脚本中从另一个电子表格编辑一个电子表格 - Editing one Spreadsheet from another Spreadsheet in Google Apps Script 使用 Google Apps 脚本将一个 Google 电子表格中的特定数据复制到另一个 Google 电子表格 - Copy Specific Data in one Google Spreadsheet to another Google Spreadsheet with Google Apps Script 将工作表复制到另一个电子表格[Google Apps脚本] - Copy sheet to another spreadsheet [Google Apps Script]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM