c# - Datatable export to excel working for ".xls" format but giving error for ".xlsx" format -


i have following code download datatable excel file.this code working if download ".xls" format , not working if download ".xlsx" format.

var filename = "students.xlsx"; var sw = new system.io.stringwriter(); var hw = new system.web.ui.htmltextwriter(sw); var grid = new system.web.ui.webcontrols.datagrid(); grid.datasource = dt; grid.databind();  //customizing format grid.headerstyle.backcolor = system.drawing.color.lightgray; grid.headerstyle.font.bold = true;  grid.rendercontrol(hw);  //string style = @"<style> .textmode { mso-number-format:\@; } </style>";  response.clear(); response.buffer = true; //response.contenttype = "application/vnd.ms-excel"; response.contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; response.appendheader("content-disposition", "attachment; filename=" + filename + ""); response.write(sw.tostring()); response.flush(); response.end(); 

if download ".xlsx" format giving following error , unable open excel file.how can download excel ".xlsx" format ?

enter image description here


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -