Home > Back-end >  Google Apps Script - how to access to single values in a CSV file?
Google Apps Script - how to access to single values in a CSV file?

Time:09-26

have a CSV File on Google Drive. Can access it an see the values. But got only the hole line.

function importCSVFromGoogleDrive() {
    
      var file = DriveApp.getFilesByName('file2.csv').next();
      Logger.log(file.getSize());
      Logger.log(file.getName());
      Logger.log(file.getDateCreated());
      var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());

      var contdata = csvData[1].toString();

      Logger.log(csvData[1]);
}
Ausführungsprotokoll
06:20:12
Hinweis
Ausführung begonnen
06:20:13
Info
67.0
06:20:13
Info
file2.csv
06:20:13
Info
Thu Sep 23 15:02:18 GMT 02:00 2021
06:20:13
Info
['Anna', 'Weizenkeim', '[email protected]']
06:20:14
Hinweis
Ausführung abgeschlossen

How to the for example only the email address / value 3.


function importCSVFromGoogleDrive() {
    
      var file = DriveApp.getFilesByName('file2.csv').next();
      Logger.log(file.getSize());
      Logger.log(file.getName());
      Logger.log(file.getDateCreated());
      var csvData = Utilities.parseCsv(file.getBlob().getDataAsString());

      var contdata = csvData[1].toString();

      var group = ContactsApp.getContactGroup("System Group: My Contacts");
      //bla = contdata.toUpperCase();
      Logger.log(csvData[1].toLocaleString());
      console.log(JSON.stringify(csvData[1],null,' '));
}

08:47:28 Info [ "'Anna'",
"'Weizenkeim'", "'[email protected]'" ]

CodePudding user response:

Just access the third element of the data.

      var contdata = csvData[1].toString();
      var email = csvData[1][2];
      Logger.log(email);
  • Related