I would like to convert the Google Spread Sheet created using Google Apps Script into an Excel (xlsx) file and send it as an attachment through Gmail (MailApp).
I used the code below, but there is an error, so please check it.
Exception: Converting from application/vnd.google-apps.spreadsheet to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet is not supported.
//send email
var emailTitle = noteSheet.getRange(2,2).getValue();
var emailContent = noteSheet.getRange(3,2).getValue();
var emailRecipient = noteSheet.getRange(4,2).getValue();
var emailCarboncopy = noteSheet.getRange(5,2).getValue();
var paymentfileName = paymentSheet.getRange(2,2).getValue();
var paymentXlsx = DriveApp.getFilesByName(paymentfileName);
if (!paymentXlsx.hasNext()) {
throw new Error("No paymentXlsx file.");
}
var paymentXlsx = paymentXlsx.next();
MailApp.sendEmail(emailRecipient, emailTitle, emailContent, {
name: 'name',
cc: emailCarboncopy,
attachments: [paymentXlsx.getAs(MimeType.MICROSOFT_EXCEL)]
});
}