Copy a complete list on one spreadsheet to append on the bottom of another spreadsheet

前端 未结 2 934
陌清茗
陌清茗 2020-12-20 05:03

In Google Spreadsheet I would like to take only the values from a complete list on one spreadsheet and append it to the bottom of a list on another spreadsheet. My trouble i

相关标签:
2条回答
  • 2020-12-20 05:32

    As you've found, copyValuesToRange() is a Range method that affects a Sheet Object that is in the same Spreadsheet Object as the Range. There isn't an atomic method that will copy a range of values to another Spreadsheet, but there are a number of ways you could do it.

    Here's one way.

    • From the source sheet, get all the data in one operation, by selecting the complete range of data using getDataRange() and then grabbing all values into a javascript array with getValues().
    • To ignore the first row of headers, use the javascript array method splice().
    • Locate your destination, which is on the target sheet, starting after the last row of data that's currently there, using getLastRow().
    • Write the source data (without the headers) to the destination sheet starting at the next row, using setValues().

    Script:

    function transferList() {
      var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("RFP List");
      var sourceData = sourceSheet.getDataRange().getValues();
      sourceData.splice(0,1);  // Remove header
      var targetSS = SpreadsheetApp.openById("0ABCD").getSheetByName("RFPData");
      var targetRangeTop = targetSS.getLastRow(); // Get # rows currently in target
      targetSS.getRange(targetRangeTop+1,1,sourceData.length,sourceData[0].length).setValues(sourceData);
    }
    
    0 讨论(0)
  • 2020-12-20 05:44

    For some historic dashboard I created by importing and appending data, I use an add-on called Sheetgo. Save me programing time and help me with traceability issues.

    0 讨论(0)
提交回复
热议问题