DEV Community

Cover image for How to export Google Spreadsheet as MS Excel File
kaushikmw
kaushikmw

Posted on

How to export Google Spreadsheet as MS Excel File

Many times we want to send the Google Spreadsheet as a MS Excel attachment to external email id. There is one way to the file as blob as below

DriveApp.getFileById('AASD12asdA3as').getBlob()
but this will return the file as "PDF" by default.
So to get the file in MS Excel format, one can use below code
var oExportedFile = UrlFetchApp.fetch( Drive.Files.get('AASD12asdA3as').exportLinks['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
{
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
}
}
);

Well, this will give us a MS Excel file but the name will be "exports.xlsx", irrespective of the original Google Sheet name! So, to set a custom name, add below line

var oXslFile = DriveApp.createFile(oExportedFile.getBlob()).setName('Custom File Name');

To get MS Document or presentation file, all you need to do is to change the parameter passed to exportLinks property. To know all the possible values, please visit this link

Hope this helps you!
Regards

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay