0
votes

I get a zipped csv file sent by email weekly and have written a google app script to get the file from email and save to drive:

   // unzip it
   var unzipblob = Utilities.unzip(att[z]);

   // Create with a unique filename using date of email
   var newName = 'provider_stats-' + Utilities.formatDate(date, 'GMT', 'yyyy-MM-dd') + '.csv';

   // Save the first file (there's only one) in the zip
   file = folder.createFile(newName, unzipblob[0].getDataAsString());
   file.setDescription(newName);

This works fine, but I notice in the drive folder where I save it, it seems to have a different doc-type to the ones I did manually. The other ones offer me "Open in Google Sheets" as an option when I right-click, but not the one saved from the script.

Any idea how I can set the document type or format, so it can be opened directly in Google Sheets?

My next step is to save as a Google Sheet directly, so any help on that ahead of time would also count as an answer!

1

1 Answers

0
votes

Found it, much easier that I thought!

Just set the MIME type of the file to "text/csv" using the Drive Folder method:

file = folder.createFile(newName, unzipblob[0].getDataAsString(), "text/csv");

Then GSheets is a right-click option!