see07 Posted November 25, 2004 Posted November 25, 2004 I�m using this code to export data from a datagrid to an Excel sheet: Response.Clear(); Response.Buffer= true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "inline;filename=Clientes.xls"); Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); DataGrid1.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End(); And this is working fine. But now I want to do same with a datalist and thus I changed RenderControl line thus: DataList1.RenderControl(oHtmlTextWriter); Yet when Excel sheet is showing on screen, all data are displayed in one simple column �A�, with one row for each data in datalist. Does somebody know how can I attain it work as I did as datagrd (each column in datalist into its respective column in Excel)? I�ll appreciate your suggestions. A.L. Quote
mike55 Posted August 11, 2005 Posted August 11, 2005 Hi A.L. I am using the same code as yourself for taking the data stored in my datagrid an putting it in an excel file. I am however encountering a problem. "I believe the problem is related to Microsoft Windows Service Pack 2." I have surrounded the above code with a try catch statement, and for testing purposes I threw in a "Throw Ex" statement after the catch block. From what I can figure out, the code seems to throw an exception once it reachs the final line. Any suggestions on how to prevent this error from occuring. In addition if I transfer my code to a web server and run it, if I hit the save button, the excel file will be save to my web server? Mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Recommended Posts