Converting from application/vnd.google-apps.spread

2019-08-17 13:13发布

问题:

i wrote here few hours ago about this code and here i am again, it's almost ready but i don't know why it's giving me back this error: Converting from application/vnd.google-apps.spreadsheet to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet is not supported.

So, when MimeType is pdf it works fine, email is sent and i've got the file attached, but our supplier have to get .xlsx file... So i've tried excel_legacy, GOOGLE_SHEETS ( when using this it asks me for blob which is not defined.

function sendOrder() {
  var ui = SpreadsheetApp.getUi();
  var response = ui.alert('Are you sure you want to send the order?', ui.ButtonSet.YES_NO);
  var deliveryDate = ui.prompt('Delivery date:');

  // Process the user's response.
  if (response == ui.Button.YES) {
  // Message in email \/
  var a = 'message1';
  var b = 'message2';
  var c = 'message3';
  //Divided as the message includes date of delivery between sentences (it could be done way easier, but who cares, it works
  var d = deliveryDate.getResponseText(); 
  //ID of the delivery sheet
  var s = SpreadsheetApp.openById('1pON34oXVhlpC8goyBxfu6-Gw92tgQBUVUpskZUtgp4E');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var message = [a + d + b + c + d]
  var file = DriveApp.getFilesByName('NAME');
  if (file.hasNext()) {
  var emailAddress = 'example@example.com';
  var subject = 'subject ' + deliveryDate.getResponseText();

  //Function sending emails with attached file
  MailApp.sendEmail(emailAddress, subject, message, {
  attachments: [file.next().getAs(MimeType.MICROSOFT_EXCEL)],
  })}

  SpreadsheetApp.getUi().alert('Yeah! Your order has been sent :)')}};

I'm sorry for putting in whole code, but i think it will help to understand a bit more. I believe i'm close, but i can't get it...