CSV import (which is inside a zip) automatically received by email to the Spreadsheet

Asked

Viewed 25 times

1

What happens is that every day I receive an email with a report attached. This attachment is zipped(.zip), and inside this zip has a CSV file.

I need this zip to be converted to CSV and this CSV to automatically go from my email (gmail) to the google sheet on a specific page. I wrote a script, but I’m having second thoughts about where I’m going. It says that the argument is invalid on line 10(var extracted...)

function getCSV() {
  var myLabel = GmailApp.getUserLabelByName('Relatórios X');
  var threads = myLabel.getThreads(0,1);
  var msgs = GmailApp.getMessagesForThreads(threads);
  var attachments = msgs[0][0].getAttachments();



  var csv =  attachments[0];
  var extracted = Utilities.unzip(csv);
  var string = extracted[0].getDataAsString();
  var data = Utilities.parseCsv(string);



  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Relatório_aqui");
sheet.clearContents();
  var range = sheet.getRange(1,1, data.length,data[0].length);
range.setValues(data);


}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.