Send E-mail with xlsx File Converted from Spreadsheet

This is a script to send e-mail with a xlsx file converted from spreadsheet as an attachment file. Access token is necessary to use this script.

function excelSender() {
  var accesstoken = "[your accesstoken]";
  var sheetID = "[sheet id]";
  var xlsxName = "[output xlsx file name]"
  var params = {
    "headers" : {Authorization: "Bearer " + accesstoken},
    "muteHttpExceptions" : true
  var dUrl = "" + sheetID + "/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  var xlsxlFile = UrlFetchApp.fetch(dUrl, params).getBlob().setName(xlsxName);
    to: "[your mail address]",
    subject: "sample mail",
    body: "sample mail with an excel file",
    attachments: [xlsxlFile]