javascript - Export html to Excel : when try to open file it gives prompt like file is corrupted -


i exporting html table excel using javascript code on browser. done when try open file in microsoft excel gives prompt :

"excel cannot open file 'filename.xlsx' because file format file extension not valid. verify file has not been corrupted , file extension matches format of file.do want open file now?"

if press yes works fine , data gets displayed in excel.

i want remove prompt.

my javascript code

function fnexcelreport() { var tab_text="<table border='2px'><tr bgcolor='#87afc6'>"; var textrange; var j=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 table tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in table tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params  var ua = window.navigator.useragent; var msie = 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,"data.xls"); }    else{}                  var = document.createelement('a');     a.href = 'data:application/vnd.ms-excel,' +  encodeuricomponent(tab_text);     a.download = 'rxe_data' + '.xls';     a.click(); } 

in end seems isn't possible bypass alert. if convert html code excel data open in excel, implemented server side code generate pure excel , return client instead of html data.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -