Home > Net >  Import Google Sheet Data all at once to an existing sheet with data
Import Google Sheet Data all at once to an existing sheet with data

Time:07-07

Currently I have been using this script which imports data from a spreadsheet located in my google drive. The function works but imports the data one line at a time. Some times these sheets are 400 rows and that takes a long time. I am looking for it to grab all data and import it into an existing spreadsheet and the end of the last value.

function getData() {

get_files = ['July1-2022'];
  
  var ssa = SpreadsheetApp.getActiveSpreadsheet();
  var copySheet = ssa.getSheetByName('CancelRawData');  
  
  for(z = 0; z < get_files.length; z  )
  {
  
    var files = DriveApp.getFilesByName(get_files[z]);
    while (files.hasNext()) 
    {
      var file = files.next();
      break;
    }
  
    var ss = SpreadsheetApp.open(file);
    SpreadsheetApp.setActiveSpreadsheet(ss);
    var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
    for(var i = 0; i < sheets.length; i  )
    {  
      var nameSheet = ss.getSheetByName(sheets[i].getName()); 
      var nameRange = nameSheet.getDataRange();
      var nameValues = nameRange.getValues();
      
      for(var y = 1; y < nameValues.length; y  )
      {
        copySheet.appendRow(nameValues[y]); 
      }
    }
  }
  SpreadsheetApp.getUi().alert("           
  • Related