Export DataGrid to Excel Problem with Code.
-
Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)
HtmlForm form = new HtmlForm(); string attachment = "attachment; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter stw = new StringWriter(); HtmlTextWriter htextw = new HtmlTextWriter(stw); form.Controls.Add(gvEmployee); this.Controls.Add(form); form.RenderControl(htextw); Response.Write(stw.ToString()); Response.End();
Please let me know what is the changes required in this code.
-
Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)
HtmlForm form = new HtmlForm(); string attachment = "attachment; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter stw = new StringWriter(); HtmlTextWriter htextw = new HtmlTextWriter(stw); form.Controls.Add(gvEmployee); this.Controls.Add(form); form.RenderControl(htextw); Response.Write(stw.ToString()); Response.End();
Please let me know what is the changes required in this code.
Hi, I think you should set the encoding to UTF-8. Have a look at this thread which has answer(4th post by user lionscub). Export DataGrid To Excel[^] Free attachment You may need this too.(For Ex, large numbers get converted to the (ugly) x.xxxxxxE-yy syntax. ) Datagrid to Excel Formatting Tip[^]
thatraja |Chennai|India|
Brainbench certifications
My Dad had a Heart Attack on this day so don't... -
Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)
HtmlForm form = new HtmlForm(); string attachment = "attachment; filename=Employee.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter stw = new StringWriter(); HtmlTextWriter htextw = new HtmlTextWriter(stw); form.Controls.Add(gvEmployee); this.Controls.Add(form); form.RenderControl(htextw); Response.Write(stw.ToString()); Response.End();
Please let me know what is the changes required in this code.
hi, here is the code Exporting DataGrid to Excel, Word and Text Files[^] Thanks,