Created
December 21, 2019 00:16
-
-
Save gdalgas/7cd07ee3f6de422cd8050c76fb16a503 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function importCSVFromGmail() { | |
var threads = GmailApp.search("redacted"); | |
var message = threads[0].getMessages().pop(); | |
var attachment = message.getAttachments()[0]; | |
if (attachment != null) { | |
var attachName = attachment.getName(); | |
// Is the attachment a CSV file | |
if (attachName.substring(attachName.length-4) === ".csv") { | |
var id = "redacted"; | |
var name = "Data Sheet"; | |
var sheet = SpreadsheetApp.openById(id); | |
var tab = sheet.getSheetByName(name); | |
// Clear the content of the sheet | |
var csvData = Utilities.parseCsv(attachment.getDataAsString(), ","); | |
tab.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment