Mail Google Sheet as Excel table with script

by DSS   Last Updated September 11, 2018 16:03 PM

I want to mail Google Spreadsheet as excel attachment, and I also want to multiple people to look in (To. & CC), And also I want to write some message in the body. I have the script and when I use that script I am getting Google Spreadsheet as excel, I am not able to add other people in a loop (To & CC). With the script I have, if I add another person, it would be added but when email was sent another person can't see who are on the mailing list. If there is any script Please help me with that.

I am sharing the script code which I have:

unction onOpen() { 
  // Try New Google Sheets method
    var ui = SpreadsheetApp.getUi();
    .addItem('Send Report', 'getGoogleSpreadsheetAsExcel')

  // Log the error
  catch (e){Logger.log(e)}


function getGoogleSpreadsheetAsExcel(){

  try {

var ss = SpreadsheetApp.getActive();

var url = "" + ss.getId() + "&exportFormat=xlsx";

var params = {
  method      : "get",
  headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
  muteHttpExceptions: true

var blob = UrlFetchApp.fetch(url, params).getBlob();

blob.setName(ss.getName() + ".xlsx");

MailApp.sendEmail("", "Stock report of today", "The XLSX file is attached", {attachments: [blob]});

} catch (f) {

Related Questions

Which is better: onEdit or onChange trigger?

Updated August 14, 2018 16:03 PM

How to format the time in this Google Docs script

Updated July 12, 2018 14:03 PM

How to Process Rows of Google Sheet Singly?

Updated April 05, 2018 19:03 PM