I have an email that comes everyday with an attached .xls (sometimes a CSV) spreadsheet file. I would like to import this SS everyday and have the new content added to the next available rows.
How do I adjust this script to do that action?
I would like to have this script add the content to a specific sheet/tab.
In addition, how would I make this script look for a specific label instead of my primary inbox to pull the file from?
Reference of script: Import CSV from Gmail attachment into Google Sheets
function importCSVFromGmail() {
var threads = GmailApp.search("from:Email Address Here");
var messages = threads[0].getMessages();
var message = messages[messages.length - 1];
var attachment = message.getAttachments()[1];
// Is the attachment a CSV file
attachment.setContentType('text/csv');
//attachment.setContentTypeFromExtension();
if (attachment.getContentType() === "text/csv") {
var sheet = SpreadsheetApp.getActiveSheet();
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ",");
// Remember to clear the content of the sheet before importing new data
sheet.clearContents().clearFormats();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
}