I am using the following Javascript code to generate an excel on the fly, which converts HTML table to a spreadsheet.
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 encoding
function ExcelReport() {
var tab_text = '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
tab_text = tab_text + '<head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>';
tab_text = tab_text + '<x:Name>Test Sheet</x:Name>';
tab_text = tab_text + '<x:WorksheetOptions><x:Panes></x:Panes></x:WorksheetOptions></x:ExcelWorksheet>';
tab_text = tab_text + '</x:ExcelWorksheets></x:ExcelWorkbook></xml></head><body>';
tab_text = tab_text + "<table>";
var headingTable = $('#h_tbl').clone();
tab_text = tab_text + headingTable.html();
tab_text = tab_text + '</table>';
$('.c_tbl').each(function( index ) {
tab_text = tab_text + "<table>";
tab_text = tab_text + "<tr><td></td></tr><tr><td></td></tr>";
tab_text = tab_text + '</table>';
tab_text = tab_text + "<table>";
var exportTable = $(this).clone();
tab_text = tab_text + exportTable.html();
tab_text = tab_text + '</table>';
});
tab_text = tab_text + '</body></html>';
var fileName = name + '.xls';
var blob = new Blob([tab_text], { type: "application/vnd.ms-excel;charset=utf-8" })
window.saveAs(blob, wo_var + ".xls");
}
When I open the excel in notepad the html code looks like the following
<html xmlns:x="urn:schemas-microsoft-com:office:excel"><head><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>
<tbody><tr><td>abc:</td></tr></tbody></table></body></html>
See Question&Answers more detail:os