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

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

问题描述:

我想将SORT QUERY正在执行的操作(在代码的.getRange行上方)合并到此脚本中.因此,除了复制A2:F之外,我还将B列,C列,D列和E列从ONLINESendNewSkusToGID复制到RECTOONLINE.

I would like to incorporate the action the SORT QUERY is doing (above .getRange line of code) in this script. So instead of copying A2:F I would get Column B, C, D, E copied from ONLINESendNewSkusToGID to 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();
}

预先感谢

解决方案

这是将B到E列从一张纸复制到另一张纸的代码段.让我知道这是否是您要解决的问题.

Solution

Here is the code snippet that copies the columns B to E from one sheet to other. 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);
}

有关如何获取和设置值的更多信息,请查看 here 此处.希望这对您有所帮助,请告诉我您是否还需要其他内容或不了解任何内容.

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.