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

你离开我真会死。 提交于 2020-03-05 01:30:37

问题


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();
}

Thanks In Advance


回答1:


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);
}

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.



来源:https://stackoverflow.com/questions/60374647/modify-code-copy-certain-rows-columns-from-one-spreadsheet-to-another-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!