Click here to Skip to main content
14,425,437 members
Rate this:
Please Sign up or sign in to vote.
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:

  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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100