title: How to export an HTML table as a .xlsx file
body: <p>I have a question about exporting an <strong>HTML table</strong> as an <strong>xlsx</strong> file. I did some work and now I can export it as an <strong>xls</strong>, but I need to export it as an <strong>xlsx</strong>.</p>
  
  <p><strong>Here is my jsFiddle:</strong> <a href="https://jsfiddle.net/272406sv/1/" rel="noreferrer">https://jsfiddle.net/272406sv/1/</a></p>
  
  <p><strong>Here is my HTML:</strong></p>
  
  <pre><code>&lt;table id="toExcel" class="uitable"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Kampanya Basligi&lt;/th&gt;
        &lt;th&gt;Kampanya Türü&lt;/th&gt;
        &lt;th&gt;Kampanya Baslangiç&lt;/th&gt;
        &lt;th&gt;Kampanya Bitis&lt;/th&gt;
        &lt;th style="text-align: center"&gt;Aksiyonlar&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr ng-repeat="Item in campaign.campaignList"&gt;
        &lt;td&gt; Item.CampaignTitle &lt;/td&gt;
        &lt;td&gt; Item.CampaignHotelType &lt;/td&gt;
        &lt;td&gt; Item.CampaignHotelCheckInDate) &lt;/td&gt;
        &lt;td&gt;Item.CampaignHotelCheckOutDate&lt;/td&gt;
        &lt;td style="text-align: center"&gt;
          &lt;button&gt; Some Action &lt;/button&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;button onclick="exceller()"&gt;EXCEL&lt;/button&gt;
  </code></pre>
  
  <p><strong>Here is my JavaScript code:</strong></p>
  
  <pre><code>&lt;script&gt;
    function exceller() {
      var uri = 'data:application/vnd.ms-excel;base64,',
        template = '&lt;html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"&gt;&lt;head&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:Name&gt;{worksheet}&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:DisplayGridlines/&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;',
        base64 = function(s) {
          return window.btoa(unescape(encodeURIComponent(s)))
        },
        format = function(s, c) {
          return s.replace(/{(\w+)}/g, function(m, p) {
            return c[p];
          })
        }
      var toExcel = document.getElementById("toExcel").innerHTML;
      var ctx = {
        worksheet: name || '',
        table: toExcel
      };
      var link = document.createElement("a");
      link.download = "export.xls";
      link.href = uri + base64(format(template, ctx))
      link.click();
    }
  &lt;/script&gt;
  </code></pre>