Export To Excel Even With Special Character in Data
The Following C# code is used to Export data from ASP.NET to Excel with special characters
try
{
Response.ContentType = "application/vnd.ms-excel 8.0";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
this.EnableViewState = false;
System.IO.StringWriter ObjWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter ObjHtmlTextWriter = new System.Web.UI.HtmlTextWriter(ObjWriter);
rptUserDetails.RenderControl(ObjHtmlTextWriter);
//dgdInitiative is the Grid name which is to be exported
Response.Write(ObjWriter.ToString());
string strhtml = ObjHtmlTextWriter.ToString();
Response.AppendHeader("content-disposition", "attachment;filename=Users.xls");
Response.End();
}
catch (System.Exception ex)
{
string strMsg = ex.Message;
}
try
{
Response.ContentType = "application/vnd.ms-excel 8.0";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
this.EnableViewState = false;
System.IO.StringWriter ObjWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter ObjHtmlTextWriter = new System.Web.UI.HtmlTextWriter(ObjWriter);
rptUserDetails.RenderControl(ObjHtmlTextWriter);
//dgdInitiative is the Grid name which is to be exported
Response.Write(ObjWriter.ToString());
string strhtml = ObjHtmlTextWriter.ToString();
Response.AppendHeader("content-disposition", "attachment;filename=Users.xls");
Response.End();
}
catch (System.Exception ex)
{
string strMsg = ex.Message;
}
Comments
Thanks a lot.