Click here to Skip to main content
15,917,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone,
I am trying to export my gridview which has datatable as datasource but excel sheet is not created properly, its shows "डाटा उपलब्ध हुन सकेन!!" in excel sheet. I have unicode values in gridview(hindi values), below is my code, plz suggest me where I did mistake. Same code work if my datasource is Sqldatasource object...plz help...
C#
 public void ExporttoExcel(GridView gv)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.AddHeader("content-disposition",        string.Format("attachment; filename={0}", "Customers.xls"));
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);            
            gv.AllowPaging = false;
            gv.DataBind();           
            gv.HeaderRow.Style.Add("background-color", "#FFFFFF");        
            gv.RenderControl(htw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();
           
        }
 protected void btnExcel_Click(object sender, ImageClickEventArgs e)
    {

        at.ExporttoExcel(gvDailyAttendenceReport);
    }
protected void btnShow_Click(object sender, EventArgs e)
    {
        showDailyAttendance();//function to bindgridview (datatable as datasource)
    }
Posted
Updated 20-Jun-13 2:45am
v2

1 solution

Refer - Currency code comes with Unicode while export to excel[^].
Quote:

C#
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
 
Share this answer
 
Comments
Gopal Rakhal 21-Jun-13 1:16am    
I have already tried this but not working any other alternative ..
Gopal Rakhal 21-Jun-13 1:28am    
Atlast I solved, its just bcoz of line "gv.DataBind()" in ExporttoExcel(GridView gv)
Ok, cool. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900