title: Converting Google Spreadsheet to Excel with AppScript and send it via email
body: <p>I made a question in how to <a href="https://stackoverflow.com/questions/32334300/converting-google-spreadsheet-to-excel-with-appscript-2015">Convert Google Spreadsheet to excel with AppScript 2015</a></p>
  
  <p>and been guided to the answer in this other post <a href="https://stackoverflow.com/a/27281729/1677912">https://stackoverflow.com/a/27281729/1677912</a></p>
  
  <p>It seemed to work, but I had a new problem: the created file is smaller than it should be, and doesn't open (corrupted). Here is the complete code:</p>
  
  <pre><code>function crearBackUp() {
  
  //pone en la variable -sheet- a la hoja activa
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  
  //obtiene la fecha para ponerle al nombre del archivo
  var d = new Date();
  var mes = d.getMonth() + 1;
  var anio = d.getFullYear();
  
  var nombre = "backUP_BaseDatos_BN_"+mes.toString()+anio.toString();
  
  //creo una copia y obtengo el ID para pasarlo a Drive
  var theBKP = sheet.copy(nombre);
  var theID = theBKP.getId();
  
  //Abro el arch con Drive y exporto a XLS
  var file = Drive.Files.get(theID);
  var url = file.exportLinks[MimeType.MICROSOFT_EXCEL];
  
  var response = UrlFetchApp.fetch(url);      
  var doc = response.getBlob();
  
  //crea el archivo con DriveApp pasasndole el Blob
  var theFile = DriveApp.createFile(doc).setName(file.title + '.xlsx');
  
  //Manda el mail
  MailApp.sendEmail('email@gmail.com', 'Subject','Mensaje',   {
    filename: nombre,
    attachments: theFile
    })
  }
  </code></pre>
  
  <p>I wonder if there isn't an easier or more direct method to do it, as this is for me quite a workaround.</p>