title: Problem importing a large .csv file into Google Sheets
body: <p>I have designed a Dashboard in Google Data Studio based on one Google Sheets file. The data that goes into the Google Sheets file comes from two .csv files separated by &quot;;&quot;. These .csv files are automatically updated at night and stored on the Google Drive. In order for my Dashboard to also automatically update based on the changes in the .csv files I need to automatically read them into the Google Sheets file, which I do by triggering my script to run every night after the .csv files have gotten updated...</p>
  <p>As I do not really know how to code besides from some basics I build the following script from various sources throughout the Internet. The nice thing is, that it basically works:</p>
  <pre><code>function parseCsv(csvString, delimiter) {
    var sanitizedString = csvString.replace(/([&quot;'])(?:(?=(\\?))\2[\s\S])*?\1/g, function(e){return e.replace(/\r?\n|\r/g, ' ') });
    return Utilities.parseCsv(sanitizedString, delimiter)
  }
  
  //------------------------------------------------------------
  
  function import_Sales() {                    
   var fileName = &quot;exported_Sales.csv&quot;;
  
   var searchTerm = &quot;title = '&quot;+fileName+&quot;'&quot;;
   var files = DriveApp.searchFiles(searchTerm)
   var csvFile = &quot;&quot;;
  
   while (files.hasNext()) {
     var file = files.next();
  
     if (file.getName() == fileName) {
       csvFile = file.getBlob().getDataAsString('ISO-8859-15');
       break;
     }
   }
  
   var csvData = parseCsv(csvFile,&quot;;&quot;);
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheetByName('ExportSales');
   sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
  }
  </code></pre>
  <p>As already mentioned I am importing 2 different .csv files (so there is not only the import_sales function but also an import_stock function.</p>
  <p>For the stocks csv everything works really fine (it looks exactly like the import_Sales() function above, besides the names of course).</p>
  <p>The problem seems to be the size of my sales-.csv file. (23 columns x 56.000 rows) and the file is getting longer every night when it is being updated. So when trying to run the <code>import_Sales</code> function after some minutes i get the error &quot;maximum execution time&quot;... So I get that this must have something to do with the size of the .csv or the function (hopefully) being inefficient and maybe someone of you has an idea how it could run faster? The size of the .csv can not be changed and i can't imagine that it shall be impossible to import it to google Sheets?!</p>
  <p>Has anyone an idea how I can manage it to get the data from the csv into Google Sheets automatically every night? Maybe I could skip the row that are already in the google sheets file and just import the new lines from the cvs somehow? But that's where my knowledge comes to an end definitely.</p>