I have as series of Google Apps Scripts that seem to work well with converting .xlsx attachments from my Gmail and saving them as Google Sheets in my Drive.
Unfortunately, I'm not having luck duplicating that process to an .xlsx file that I'm trying to download from a specific URL.
Here's the code:
// Fetch the URL and convert it to a blob
var url = ** URL with the file **;
var response = UrlFetchApp.fetch(url);
var uniqueFeed = Utilities.newBlob(response, "application/vnd.ms-excel", "Unique.xlsx");
var fileToImport = DriveApp.createFile(uniqueFeed);
That DOES create the file in my Drive. However, it's corrupt. When I console.log the blob as a string, I get a bunch of random junk (for example):
[20-06-29 15:35:49:776 CDT] PK�����!�v��������[Content_Types].xml �(������������������������������������������������������������������������������������������������������������������������U�N�0�#����q�!Ԕ�$�L�M�:���B���MA�C��$�cg�c{2�^t����ƻJ��CQ���6�������RH�ie��J,����d���W;�DK��ĺ�Na�8���)�fldP�L5 G�ᅬ
My code to convert the .xlsx file then fails, I'm ASSuming because the newly created file is no good. I also don't get why it mentions .xml. The URL and the file are definitely .xlsx.
Just to clarify one thing: If I manually download the file from the URL to my computer, and then drop it into my Drive, I CAN convert it to a Google Sheet without issue. I'm trying to automate that manual step out... hence the problem.
Any insights would be much appreciated. I can PM the URL upon request -- just don't want it floating around the interwebs.