title: Import data from a single column of CSV file in Google Apps Script
body: <p>I'm using Google Apps Script to import data from a CSV file where the datas are in a single column. I'm following <a href="https://developers.google.com/apps-script/articles/docslist_tutorial?hl=en#section-2-importing-data-from-a-csv-file" rel="nofollow noreferrer">this tutorial</a> to read datas from CSV file but since the datas are in single column, comma delimiter is not working and the code is hanging whenever I run the function.</p>
  <p>Here is my code:</p>
  <pre><code>function importCSV(getfile) {
      getfile = &quot;Copy of FR1_1.csv&quot;;
      var getFolder = DriveApp.getFolderById(fId);
      var fi = getFolder.getFilesByName(getfile);
  
      if (fi.hasNext()) { 
          var ssNew = SpreadsheetApp.getActiveSpreadsheet();
          var newSheet = ssNew.getSheetByName(&quot;Sheet1&quot;);
          var file = fi.next();
          var csv = file.getBlob().getDataAsString();
          var csvData = CSVToArray(csv); // see below for CSVToArray function
          // loop through csv data array and insert (append) as rows into the sheet
          for (var i = 0; i &lt; csvData.length; i++) {
              newSheet.getRange(newSheet.getLastRow()+1, 1, csvData.length).setValues(new Array(csvData[i][0]));
          }
          Browser.msgBox(&quot;CSV imported successfully!&quot;);
      }
  }
  
  function CSVToArray(strData, strDelimiter) {
      // Check to see if the delimiter is defined. If not,
      // then default to COMMA.
      strDelimiter = (strDelimiter || &quot;,&quot;);
  
      // Create a regular expression to parse the CSV values.
      var objPattern = new RegExp(
          (
              // Delimiters.
              &quot;(\\&quot; + strDelimiter + &quot;|\\r?\\n|\\r|^)&quot; +
  
              // Quoted fields.
              &quot;(?:\&quot;([^\&quot;]*(?:\&quot;\&quot;[^\&quot;]*)*)\&quot;|&quot; +
  
              // Standard fields.
              &quot;([^\&quot;\\&quot; + strDelimiter + &quot;\\r\\n]*))&quot;
          ),
          &quot;gi&quot;
      );
  
      // 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(&quot;\&quot;\&quot;&quot;, &quot;g&quot;),
                  &quot;\&quot;&quot;
              );
  
          } 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>
  <p>How can I import datas from a single column of CSV file in spreadsheet?</p>