internet explorer 8 - Exporting HTML table to Excel, file created but encoded HTML inside Excel sheet -


i exporting html table excel file. using other browsers:

window.open('data:application/vnd.ms-excel,<meta http-equiv="content-type" content="text/plain; charset=utf-8"/>' + encodeuricomponent(tblhtml)); 

but ie8, have done following make export work:

  1. jquery post send table html markup string
  2. javascript doing post request:

    if (($.browser.msie && parseint($.browser.version) <= 8)) {     $.ajax({         url: '/exportdatatoexcel',         data: {             'tbltoexport': tblhtml//encodeuricomponent(tblhtml)             , 'tblid': id         },         type: 'post',         async: false,         success: function (html) {             //nothing         },         error: function (jqxhr, textstatus, errorthrown) {             if (jqxhr.readystate != 0) {                 alert('error occurred');             }         }     });      window.open("/exportdatatoexcelfilesavedialog", 'popup', 'width=500,height=300'); } 
  3. action handles post request , window.open request (for opening file save dialog):

    [httppost] [validateinput(false)] public actionresult exportdatatoexcel(formcollection form) {     string tbltoexport = form["tbltoexport"], tblid = form["tblid"];      session["exporttbl"] = tbltoexport;      contentresult content = new contentresult();     return content; } [validateinput(false)] public actionresult exportdatatoexcelfilesavedialog() {     response.contenttype = "application/vnd.ms-excel";      response.addheader("content-disposition", "attachment;filename=download.xls");     response.contentencoding = system.text.encoding.utf8;      object tbltoexport = session["exporttbl"];     return partialview("_exporttoexcelforie8", tbltoexport.tostring());  } 

now, when file save dialog opens can able save excel file excel file content is:

%0d%0a%3ctable+dir%3dltr+id%3dtblcompanalysis+class%3d%22clear+table+company-analysis-general%22+cellspacing%3d0+cellpadding%3d0+width%3d%22100%25%22%3e%3ctbody%3e%0d%0a%3ctr+class%3d%22labh+sort%22%3e%0d%0a%3ctd%3ecompany%3c%2ftd%3e%0d%0a%3ctd%3emarket+sector%3c%2ftd%3e%0d%0a%3ctd%3eargaam+sector+%3c%2ftd%3e%0d%0a%3ctd+class%3dcity%3ecity%3c%2ftd%3e%0d%0a%3ctd+class%3dtel%3ephone%3c%2ftd%3e%0d%0a%3ctd+class%3dtel%3efax%3c%2ftd%3e%0d%0a%3ctd%3eemail%3c%2ftd%3e%0d%0a%3ctd%3ewebsite%3c%2ftd%3e%3c%2ftr%3e%0d%0a%3ctr%3e%0d%0a%3ctd%3e%3c


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -