1Excel export script works on IE7+, Firefox and Chrome.
2
3function fnExcelReport()
4{
5 var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
6 var textRange; var j=0;
7 tab = document.getElementById('headerTable'); // id of table
8
9 for(j = 0 ; j < tab.rows.length ; j++)
10 {
11 tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
12 //tab_text=tab_text+"</tr>";
13 }
14
15 tab_text=tab_text+"</table>";
16 tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
17 tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
18 tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
19
20 var ua = window.navigator.userAgent;
21 var msie = ua.indexOf("MSIE ");
22
23 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
24 {
25 txtArea1.document.open("txt/html","replace");
26 txtArea1.document.write(tab_text);
27 txtArea1.document.close();
28 txtArea1.focus();
29 sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
30 }
31 else //other browser not tested on IE 11
32 sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
33
34 return (sa);
35}
36
1function fnExcelReport()
2{
3 var tab_text="<table border='2px'><tr bgcolor='#87AFC6'>";
4 var textRange; var j=0;
5 tab = document.getElementById('headerTable'); // id of table
6
7 for(j = 0 ; j < tab.rows.length ; j++)
8 {
9 tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
10 //tab_text=tab_text+"</tr>";
11 }
12
13 tab_text=tab_text+"</table>";
14 tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
15 tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
16 tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
17
18 var ua = window.navigator.userAgent;
19 var msie = ua.indexOf("MSIE ");
20
21 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
22 {
23 txtArea1.document.open("txt/html","replace");
24 txtArea1.document.write(tab_text);
25 txtArea1.document.close();
26 txtArea1.focus();
27 sa=txtArea1.document.execCommand("SaveAs",true,"Say Thanks to Sumit.xls");
28 }
29 else //other browser not tested on IE 11
30 sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
31
32 return (sa);
33}
34
1Call this function on:
2<button id="btnExport" onclick="fnExcelReport();"> EXPORT </button>
3
1Just create a blank iframe:
2<iframe id="txtArea1" style="display:none"></iframe>
3