functionFnexcelreport () {vartab_text= "<table border= ' 2px ' ><tr bgcolor= ' #87AFC6 ' >"; varTextRange;varJ=0; tab= document.getElementById (' headertable ');//ID of Table for(j = 0; J < Tab.rows.length; J + +) {Tab_text=tab_text+tab.rows[j].innerhtml+ "</tr>"; //tab_text=tab_text+ "</tr>";} tab_text=tab_text+ "</table>"; Tab_text= Tab_text.replace (/<a[^>]*>|<\/a>/g, "");//Remove if u want links in your tabletab_text= Tab_text.replace (/]*>/gi, "");//Remove if u want images in your tabletab_text= Tab_text.replace (/<input[^>]*>|<\/input>/gi, "");//reomves Input params varUA =window.navigator.userAgent; varMSIE = Ua.indexof ("MSIE"); if(Msie > 0 | |!! Navigator.userAgent.match (/trident.*rv\:11\./))//If Internet Explorer{TxtArea1.document.open ("Txt/html", "Replace"); TxtArea1.document.write (Tab_text); TxtArea1.document.close (); Txtarea1.focus (); SA=txtarea1.document.execcommand ("SaveAs",true, "Say Thanks to Sumit.xls"); } Else //Other browser not tested on IE oneSA = window.open (' Data:application/vnd.ms-excel, ' +encodeURIComponent (Tab_text)); return(SA);}
Use Javascript/jquery to export HTML table data to Excel compatible Ie/chrome/firefox