title: Export HTML Table to Excel- Doesn't Open in Office 2010
body: <p>I am using the following Javascript code to generate an excel on the fly, which converts HTML table to a spreadsheet.</p>
  
  <p>The excel file does not open in Office 2010, shows blank. The same spreadsheet opens with Openoffice. What can be the issue? Is this something related to <code>encoding</code></p>
  
  <pre><code>function ExcelReport() {
                var tab_text = '&lt;html xmlns:x="urn:schemas-microsoft-com:office:excel"&gt;';
                tab_text = tab_text + '&lt;head&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;';
                tab_text = tab_text + '&lt;x:Name&gt;Test Sheet&lt;/x:Name&gt;';
                tab_text = tab_text + '&lt;x:WorksheetOptions&gt;&lt;x:Panes&gt;&lt;/x:Panes&gt;&lt;/x:WorksheetOptions&gt;&lt;/x:ExcelWorksheet&gt;';
                tab_text = tab_text + '&lt;/x:ExcelWorksheets&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;/head&gt;&lt;body&gt;';      
                tab_text = tab_text + "&lt;table&gt;";
                var headingTable = $('#h_tbl').clone();
                tab_text = tab_text + headingTable.html();
                tab_text = tab_text + '&lt;/table&gt;';
                $('.c_tbl').each(function( index ) {
                      tab_text = tab_text + "&lt;table&gt;";
                      tab_text = tab_text + "&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;";
                      tab_text = tab_text + '&lt;/table&gt;';
                      tab_text = tab_text + "&lt;table&gt;";
                      var exportTable = $(this).clone();
                      tab_text = tab_text + exportTable.html();
                      tab_text = tab_text + '&lt;/table&gt;';
                });
                tab_text = tab_text + '&lt;/body&gt;&lt;/html&gt;';
                var fileName = name + '.xls';
                var blob = new Blob([tab_text], { type: "application/vnd.ms-excel;charset=utf-8" })
                window.saveAs(blob, wo_var + ".xls");
              }
  </code></pre>
  
  <p>When I open the excel in notepad the html code looks like the following</p>
  
  <pre><code>&lt;html xmlns:x="urn:schemas-microsoft-com:office:excel"&gt;&lt;head&gt;&lt;meta http-equiv="content-type" content="text/plain; charset=UTF-8"/&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;
          &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;abc:&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/G2PSc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G2PSc.png" alt="enter image description here"></a></p>