Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string filename = "FY15 Input Collection Template_" + ddlcity.SelectedItem.Text+".xls" ;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Charset = "UTF-8";
Response.ContentType = "application/vnd.ms-excel";
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
Microsoft.Office.Interop.Excel.ApplicationClass _ExcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
_ExcelApp.DisplayAlerts = false;
tbcity.RenderControl(hw);
tbannualpercent.RenderControl(hw);
tblasm.RenderControl(hw);
tbtwotable.RenderControl(hw);
tbsectb.RenderControl(hw);
tbthreetb.RenderControl(hw);
tbthirdtb.RenderControl(hw);
tbfourtb.RenderControl(hw);
tbfrtable.RenderControl(hw);
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.Flush();
Response.End();


when the file is downloaded and when we tring to open the excel file its showing pop-up msg "FILE EXTENSIONS WERE CORRUPTED DO YOU WANT TO OPEN ANY WAy" how can i suppress that pop up message any help please......
Posted

1 solution

You created the file in the xlsx format, but used the extension .xls. Use the .xlsx extension instead.
 
Share this answer
 
Comments
Member 10057465 15-Jan-14 6:07am    
Hi thankyou for Quick reply...
when i am using the .xlsx extension file not containg tables as i am exporting html tables to xlsx
Bernhard Hiller 15-Jan-14 6:31am    
Instead of opening the file directly on the client side, chose the save option from your browser and look at the file's contents with an appropriate editor (e.g. hexadecimal), or inspect the file otherwise: from the code you showed above, I guess that it is (almost) empty...
Member 10057465 15-Jan-14 6:47am    
I am sorry I didnt understand please guide me to export html tables to excel sheet without any pop-up message please help me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900