Click here to Skip to main content
15,886,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
iam downloading my data from sql server to execl. when i was try to open Execl file it shows
Error message with options(yes,No,Cancel):
The file you are trying to open "DetailedPurchases.xls" in a different format than specified file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
when i click yes , file opens but with white back ground( no columns). it opens fine in OpenOffice

here is my code in Controller:

C#
  List<TicketReportsModel> Obj= GetDetailedTicketPurchases(Id);
// using this iam getting data from my stored procedure to Obj

System.Web.UI.WebControls.GridView gridvw = new System.Web.UI.WebControls.GridView();
           gridvw.DataSource = Obj.ToList(); // binding data
           gridvw.DataBind();
           Response.ClearContent();
           Response.AddHeader("content-disposition",                    "attachment;filename=Detailed_Ticket.xls");
           Response.ContentType = "application/vnd.ms-excel";
           StringWriter swr = new StringWriter();
           HtmlTextWriter tw = new HtmlTextWriter(swr);
           gridvw.RenderControl(tw);
           Response.Write(swr.ToString());
           Response.End();

 i tried by changing
     Response.ContentType = "application/excel";


plz help me to find this. thanks in advance

Posted
Comments
[no name] 27-Nov-13 10:01am    
try changing .xls to .xlsx

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