Hi All, i want to export my LiteralControl of asp.net to excel workbook but m not able to do it as it is not opening a excel sheet to save but it is showing "Doumnet.aspx" file to save....here i'm giving the code of button click
protected void btnExport_excel_Click1(object sender, EventArgs e) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; // HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx"); HttpContext.Current.Response.Charset = ""; this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); ltATPCLP = (LiteralControl)(Session["exportData"]); ltATPCLP.RenderControl(hw);
string k = sw.ToString();
HttpContext.Current.Response.Write(k);
HttpContext.Current.Response.End(); }
|
any idea..... or any help please do it ASAP.
Thanks,
Amit
jouli parkerPosted Apr 17, 2010, 1:08 AM
Amit ChoudharyPosted Oct 24, 2009, 5:33 AM
but i dont have grid i have HTML table code in my Literal control so after rendering it i only get the HTML table
The code i have given here is after small modification is in running state but new problem came as the exported excel file giving
warning when opens it..." The file is not of the correct format to open in excel" but i ignore the error and open it then files opens but
no excel type view of the file i found its just seems another type forcely opens in excel...
what to do with that my client is going crazy as m getting late in delivering the product....
any idea??????
jingePosted Oct 24, 2009, 5:14 AM
http://www.dotnetspider.com/resources/2237-Create-excel-file-from-ASP-NET-datagrid-control.aspx