title: How to overcome 'Exceeded maximum execution time' in Google Apps Script?
body: <p>I think I should start by saying that I am a complete <strong>noob</strong> to all of this. Currently, I have this system where I upload .csv-s to my Google Drive and after I run a time-triggered script, they get transferred to a Google Spreadsheet file. The problem is that in recent times my .csv-s started getting slightly larger and triggered the 'Exceeded maximum execution time' pop up. I was wondering if you could help me find a workaround? I have attached my script, which in turn is based on various small scripts I found on this website.</p>
  
  <p>Is there a way I could maybe transfer just two columns (say A and F)?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>function importData() {
    var fSource = DriveApp.getFolderById("0B24o3jJdWKZ2Mk5KaVBkX0"); // reports_folder_id = id of folder where csv reports are saved
    
    
    
     
  
   var ssA = SpreadsheetApp.openById("1KxvCe4zyiYCxvjFEpCelQpB85kABpFE4gy77");
   var sheetA = ssA.getSheets()[0];
  
   var rangeA = sheetA.getRange("a1:a10");
  
   var cellA = rangeA.getCell(7, 1);
   Logger.log(cellA.getValue()); //last few rows are used to get the URL of my .csv (that has to get converted) from a sheet that serves as an inventory
   
    
    
    
    
    
    
    
    var fi = fSource.getFilesByName(cellA.getValue());
    var ss = SpreadsheetApp.openById("1KxvCe4zyiYCxvjFEpCelQpB85kABpFE4gy77"); // data_sheet_id = id of spreadsheet that holds the data to be updated with new report data
  
    if ( fi.hasNext() ) { // proceed if the previously referenced .csv file exists in the reports folder
      var file = fi.next();
      var csv = file.getBlob().getDataAsString();
      var csvData = CSVToArray(csv); // see below for CSVToArray function
      
      
      
      
      var ssB = SpreadsheetApp.getActive();
      var sheetB = ssB.getSheetByName('NEWDATA');
      ssB.deleteSheet(sheetB);
      
      
      
     
      var newsheet = ss.insertSheet('NEWDATA'); // create a 'NEWDATA' sheet to store imported data
      // loop through csv data array and insert (append) as rows into 'NEWDATA' sheet
      for ( var i=0, lenCsv=csvData.length; i&lt;lenCsv; i++ ) {
        newsheet.getRange(i+1, 1, 1, csvData[i].length).setValues(new Array(csvData[i]));
      }
     
      //** report data is now in 'NEWDATA' sheet in the spreadsheet - process it as needed,
        
      
    }
  };
  
  
  
  // This will parse a delimited string into an array of arrays.
  
  function CSVToArray( strData, strDelimiter ) {
  
    strDelimiter = (strDelimiter || ",");
  
    // Create a regular expression to parse the CSV values.
    var objPattern = new RegExp(
      (
        // Delimiters.
        "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
  
        // Quoted fields.
        "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
  
        // Standard fields.
        "([^\"\\" + strDelimiter + "\\r\\n]*))"
      ),
      "gi"
    );
  
    // Create an array to hold our data. Give the array
    // a default empty first row.
    var arrData = [[]];
  
    // Create an array to hold our individual pattern
    // matching groups.
    var arrMatches = null;
  
    // Keep looping over the regular expression matches
    // until we can no longer find a match.
    while (arrMatches = objPattern.exec( strData )){
  
      // Get the delimiter that was found.
      var strMatchedDelimiter = arrMatches[ 1 ];
  
      // Check to see if the given delimiter has a length
      // (is not the start of string) and if it matches
      // field delimiter. If id does not, then we know
      // that this delimiter is a row delimiter.
      if (
        strMatchedDelimiter.length &amp;&amp;
        (strMatchedDelimiter != strDelimiter)
      ){
  
        // Since we have reached a new row of data,
        // add an empty row to our data array.
        arrData.push( [] );
  
      }
  
      // Now that we have our delimiter out of the way,
      // let's check to see which kind of value we
      // captured (quoted or unquoted).
      if (arrMatches[ 2 ]){
  
        // We found a quoted value. When we capture
        // this value, unescape any double quotes.
        var strMatchedValue = arrMatches[ 2 ].replace(
          new RegExp( "\"\"", "g" ),
          "\""
        );
  
      } else {
  
        // We found a non-quoted value.
        var strMatchedValue = arrMatches[ 3 ];
  
      }
  
      // Now that we have our value string, let's add
      // it to the data array.
      arrData[ arrData.length - 1 ].push( strMatchedValue );
    }
  
    // Return the parsed data.
    return( arrData );
  };</code></pre>
  </div>
  </div>
  </p>