asp.net - Export Excel from grid not working on Ajax Model PopUp -


hi trying export grid data excel not working in ie8.i using ajax modal popup dialog box containing 2 buttons 'ok' , 'close'.on ok click want download excel file.it works fine in mozilla in ie not working.i using below code. please suggest me how that?also when open file first show warning before opening file how handle that?

  response.clear();     response.buffer = true;      string filename = "checkout";      response.charset = "";     response.contenttype = "application/vnd.ms-excel";     response.addheader("content-disposition", "attachment; filename=" + filename + ".adt");      response.write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");     response.write("<head>");     response.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");     response.write("<!--[if gte mso 9]><xml>");     response.write("<x:excelworkbook>");     response.write("<x:excelworksheets>");     response.write("<x:excelworksheet>");     response.write("<x:name>sheet1</x:name>");     response.write("<x:worksheetoptions>");     response.write("<x:print>");     response.write("<x:validprinterinfo/>");     response.write("</x:print>");     response.write("</x:worksheetoptions>");     response.write("</x:excelworksheet>");     response.write("</x:excelworksheets>");     response.write("</x:excelworkbook>");     response.write("</xml>");     response.write("<![endif]--> ");     response.write("</head>");      stringwriter sw = new stringwriter();     htmltextwriter hw = new htmltextwriter(sw);     gridview gv = new gridview();     gv.autogeneratecolumns = true;     gv.datasource = dt;     gv.databind();     gv.rendercontrol(hw);      response.output.write(sw.tostring());     response.flush();     response.end(); 

you warning because tehnically speaking not export excel, send html wrong headers trick browser open content excel.

better use native excel library , generate real excel file on server, example epplus, it's open source , doesn't require excel on server.

here example of ashx handler generates excel file datatable

https://stackoverflow.com/a/9569827/351383


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -