this is the fiddle
https://jsfiddle.net/shaswatatripathy/ym4egje0/7/
How to use the tableToExcel
function and make it work in Internet Explorer 11
Also It should work in Google chrome thats better . Cant use any Iframe
Objective Have to export table to excel file for IE and after much searching found this function from Generate excel sheet from html tables using jquery
but not able to use it .
HTML
<input id="btnExport" type="button" value = "Generate File" />
<table id="table">
<th>
<tr>
<td>coulmn1</td>
<td>column2</td>
</tr>
</th>
<tbody>
<tr>
<td>row1column1</td>
<td>row1column2</td>
</tr>
</tbody>
</table>
JS
$("#btnExport").click(function (e) {
TableToExcel;
});
var TableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<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"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table cellspacing="0" rules="rows" border="1" style="color:Black;background-color:White;border-color:#CCCCCC;border-width:1px;border-style:None;width:100%;border-collapse:collapse;font-size:9pt;text-align:center;">{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
if (navigator.msSaveBlob) {
var blob = new Blob([format(template, ctx)], { type: 'application/vnd.ms-excel', endings: 'native' });
navigator.msSaveBlob(blob, 'export.xls')
} else {
window.location.href = uri + base64(format(template, ctx))
}
}
})()