title: Google Script to convert a Google Sheet to Excel and Email it
body: <p>Every week I have a few different Google Sheets that I have to download as excel, delete hidden rows, fix data and then email out. </p>
  
  <p>This can be very time consuming, so I would like to make/deploy a script that automates this process.</p>
  
  <p>I did a ton of searching to try to get this to work, however I am running into a few issues.</p>
  
  <p>First, the data in the sheet is pulled via a query/importrange formula, so once downloaded to excel all data looks like the following:</p>
  
  <pre><code>=IFERROR(__xludf.DUMMYFUNCTION("""COMPUTED_VALUE"""),"No")
  </code></pre>
  
  <p>This prevents being able to filter any of the data. Currently I'm fixing this by copying all data in excel and pasting values only. I'd like the excel file to be corrected so that I don't have to do that.</p>
  
  <p>Also, I would like to be able to email the converted Excel file.</p>
  
  <p>I found the following code that works for this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getGoogleSpreadsheetAsExcel(){
    
    try {
      
      var ss = SpreadsheetApp.getActive();
      
      var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&amp;exportFormat=xlsx";
      
      var params = {
        method      : "get",
        headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
        muteHttpExceptions: true
      };
      
      var blob = UrlFetchApp.fetch(url, params).getBlob();
      
      blob.setName(ss.getName() + ".xlsx");
      
      MailApp.sendEmail("amit@labnol.org", "Google Sheet to Excel", "The XLSX file is attached", {attachments: [blob]});
      
    } catch (f) {
      Logger.log(f.toString());
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This mostly works, but again runs into the issue above of the importrange data being incorrect and showing as the =IFERROR(__xludf.DUMMYFUNCTION.</p>
  
  <p>There are also two columns (A and J) that are hidden and need to be deleted.</p>
  
  <p>Additionally, I would love to be able to change the email address, subject and message via an GUI. But this is much less important and not needed.</p>
  
  <p>I know that this is a big ask, but any help would be amazing!</p>