Google sheets sends mail with *.xlsx attachement

Hello, Hope for somebody in community can help me with appscript. I have this part well running code and it sends mails. But attached *.xlsx file includes all sheets from initial file and I want to send only 1 exact sheet, ignoring others. Please advice me, where I should state sheet name.

 
 
function Mail_excel(){
  try {

    var ss = SpreadsheetApp.getActive();
    var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + 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("usermail@mailbox.com", "Google Sheet to Excel", "The XLSX file is attached", {attachments: [blob]});

  } catch (f) {
    Logger.log(f.toString());
  }
}
Solved Solved
0 4 566
1 ACCEPTED SOLUTION

Hi  Natalia!

This is actually an AppSheet Community not a Google App Scripts (GAS) forum.   While some here might know your answer, you would probably have better luck in a dedicated GAS forum.

Having said that, you might try looking at this:  

https://support.google.com/docs/thread/105974388/script-to-automatically-send-a-sheet-by-email?hl=en

 

View solution in original post

4 REPLIES 4

Hi  Natalia!

This is actually an AppSheet Community not a Google App Scripts (GAS) forum.   While some here might know your answer, you would probably have better luck in a dedicated GAS forum.

Having said that, you might try looking at this:  

https://support.google.com/docs/thread/105974388/script-to-automatically-send-a-sheet-by-email?hl=en

 

Hello, maybe you should use something like:

 var sheet = spreadsheet.getSheetByName("SheetName")

 Please let me know if it worked. If not, that is the way.
PS: Use chat GPT or any other AI to help you make and fix the codes, that is what I do.

Thank you for brilliant idea!) It helped with some other issues as well 😊

Glad to know. 

Top Labels in this Space