Start a new topic

How to Import CSV Files into Google Sheets with Tab Delimiter

Hi,


There is a great script posted on your website, which allows you to import a CSV file into a Google Sheet. My challenge is that I want to use this script with CSV files that have a 'tab' as a delimiter... not a 'comma'.


I noticed there are some solutions in google scripts to solve this, but I am not there yet to arrange this myself.  Could you perhaps support me in adjustting this script to make it work with csv files,  which have a tab delimiter?


function importCSVFromGoogleDrive() {

  var file = DriveApp.getFilesByName("data.csv").next();
  var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}


Already thanks in advance for your support.


Regards,


Darwin



1 Comment

The parseCsv method of Google Scripts lets you specify a different delimiter so in your case, it is a tab with is written as "\t"


You can replace:


var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());


with


var csvData = Utilities.parseCsv(file.getBlob().getDataAsString(), "\t");


var csvData = Utilities.parseCsv(file.getBlob().getDataAsString(), "\t");
Login or Signup to post a comment