Q: Push the txt/csv files content grabbed from an email attachment to a spreadsheet Basically I'm grabbing emails that use a certain label, then I grab the attachment from the email which is a zip file, then I unzip its content which is a csv file, how do I push all the csv file contents into the spreadsheet?? I'm faily new so I got stuck there.
function grabAttachments(){

var label = GmailApp.getUserLabelByName("mylabel"); // The label we are trying to find
var threads = label.getThreads(); // grabs all the mails containing that label
var messages = threads[0].getMessages(); 



var attachType = messages[0].getAttachments(); //assigns attachment array to value
//Logger.log(attachType[0].getName()); //Logs Gets Attachments Name

attachType[0].getContentType(); 

var tozip = attachType[0].setContentTypeFromExtension(); // sets the content type based on the extension.
var unZip = Utilities.unzip(tozip); //assigns the unzipped file to a new variable

Logger.log(unZip[0].getContentType()); // logs the content type from the unzipped value


A: You can use the built-in Utilities.parseCsv() method to convert the CSV data into a table. 
var table = Utilities.parseCsv(unZip[0].getDataAsString());
Then, write that to the spreadsheet using Range.setValues(). A very simple way to append data to an existing sheet would be to use Sheet.getLastRow() when defining your range.
function grabAttachments(){
  var label = GmailApp.getUserLabelByName("mylabel"); // The label we are trying to find
  var threads = label.getThreads(); // grabs all the mails containing that label
  var messages = threads[0].getMessages(); 

  var attachType = messages[0].getAttachments(); //assigns attachment array to value
  //Logger.log(attachType[0].getName()); //Logs Gets Attachments Name
  attachType[0].getContentType(); 

  var tozip = attachType[0].setContentTypeFromExtension(); // sets the content type based on the extension.
  var unZip = Utilities.unzip(tozip); //assigns the unzipped file to a new variable

  Logger.log(unZip[0].getContentType()); // logs the content type from the unzipped value

  // Parse the CSV data and write to spreadsheet
  var table = Utilities.parseCsv(unZip[0].getDataAsString());
  var sheet = SpreadsheetApp.getActive().getSheetByName("Sheet1"); // Assuming a container-bound script
  sheet.getRange(
    startRow = sheet.getLastRow() + 1, // Last row has content, so write on the next row
    startColumn = 1, // Start printing in Column A
    numColumns = table.length,
    numRows = table[0].length
  ).setValues(table);
}

If you're not using a container-bound script, you won't be able to use SpreadheetApp.getActive(), so you'll need to use either SpreadsheetApp.openById() or SpreadsheetApp.openByUrl().
