Home > Blockchain >  Email Excel File as Attached for a Specified Google Sheet
Email Excel File as Attached for a Specified Google Sheet

Time:11-05

I am facing an issue in this code while sending a specific google sheet (Email) as Excel attachment.

function sendReport() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data").hideSheet();

  var message = {
    to: "[email protected]",
    subject: "Weekly Reports",
    body: "Hi Team,\n\nPlease find attached summary reports, Thanks!\n\nThank you,\nMyNameHere",
    name: "MyNameHere",
    attachments: [SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EMAIL").getAs(MimeType.xlsx).setName("Weekly Report")]
  }
  MailApp.sendEmail(message);
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EMAIL").activate();
}

The Error I am facing is:

8:36:26 PM   Notice  Execution started
8:36:27 PM   Error   TypeError: SpreadsheetApp.getActiveSpreadsheet(...).getSheetByName(...).getAs is not a function
             sendReport   @ script.gs:10

after removing

.getSheetByName("EMAIL")

from row number 10 error goes as following:

8:38:43 PM   Notice   Execution started
8:38:43 PM   Error    Exception: Invalid argument
             sendReport   @ script.gs:10

CodePudding user response:

The reason why you encountered such error is because there is no getAs() in enter image description here enter image description here

  • Related