How do you make an app script which attaches a spreadsheet as an excel file and emails it to a certain email address?
There are some older posts on Stackoverflow on how to do this however they seem to be outdated now and do not seem to work.
Thank you.
Here's an up-to-date and working version. One prerequisite for this Google Apps script to work is that the Drive API v2 Advanced Google Service must be enabled. Enable it in your Google Apps script via Resources -> Advanced Google Services... -> Drive API v2 -> on. Then, that window will tell you that you must also enabled this service in the Google Developers Console. Follow the link and enable the service there too! When you're done, just use this script.
Update: I updated the way to set the url to download from. Doing it through the file.exportLinks collection is not working anymore. Thanks to @tera for pointing that out in his answer.
It looks like @Christiaan Westerbeek's answer is spot on but its been a year now since his post and I think there needs to be a bit of a modification in the script he has given above.
There is something wrong with this line of code, maybe that
exportLinks
has now depreciated. When I executed his code it gave an error to the following effect:The workaround is as follows:
The URL in the above line of code is basically the "download as xlsx" URL that can be used to directly download the spreadsheet as an xlsx file that you get from
File> Download as > Microsoft Excel (.xlsx)
This is the format:
Check here to easily understand how to extract the ID from the URL of your google sheet.