c# - Excel file not opening after completion of download? -


by using fallowing code have exported data table excel .

response.clearcontent(); response.write(@"<!doctype html public ""-//w3c//dtd html 4.0 transitional//en"">"); response.addheader("content-disposition", attachment); response.contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; response.charset = "utf-8"; string tab = string.empty;  response.write("<font style='font-size:11.0pt; font-family:calibri;'>");  response.write("<br><br><br>");  response.write("<table border='1' bgcolor='#ffffff' bordercolor='#000000' cellspacing='0' cellpadding='0' style='font-size:11.0pt; font-family:calibri; background:white;'> <tr>");  foreach (datacolumn datacol in dt.columns) {     response.write("<td style = "+"\"width:120px;\""+">");     response.write("<b>");     response.write(tab + datacol.columnname);     response.write("</b>");     response.write("</td>"); } response.write("</tr>");  foreach (datarow dr in dt.rows) {     response.write("<tr>");     (int j = 0; j < dt.columns.count; j++)     {         response.write("<td>");         response.write(tab + convert.tostring(dr[j]));         response.write("</td>");     }      response.write("</tr>"); } httpcontext.current.response.write("</table>"); response.write("</font>"); response.flush(); response.end(); 

when trying open downloaded excel file showing following message

enter image description here

is changes needed in code . can please out this.

thanks, purna

the problem related file format find how solution in vba (just writing explicitly output format)

response.headers['content-disposition'] = 'attachment; filename=text1.xlsx' 

in code have change following line indicating explicitly output format .xlsx:

response.addheader("content-disposition", attachment); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -