Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir
Gridview to or Excel is working fine. I am using the code Mr.Nandakishorerao. it's really working fine but there was a mistake when exporting data gridview to excel below i noted the error.

Actual name:REKHA MEHTA
Given result in excel:REKHA MEHTA

Please give me the solution.
I am using following code
C#
private void excelexport()
    {
        Response.Clear(); 
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.csv"); 
        Response.Charset = ""; 
        Response.ContentType = "application/text";
        gridviewsta.AllowPaging = false;
        gridviewsta.DataBind(); 
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < gridviewsta.Columns.Count; k++) 
        { //add separator 
            sb.Append(gridviewsta.Columns[k].HeaderText + ',');
        } //append new line 
        sb.Append("\r\n");
        for (int i = 0; i < gridviewsta.Rows.Count; i++)
        {
            for (int k = 0; k < gridviewsta.Columns.Count; k++) 
                { //add separator 
                    sb.Append(gridviewsta.Rows[i].Cells[k].Text + ','); } //append new line 
                    sb.Append("\r\n"); 
                } 
        Response.Output.Write(sb.ToString()); 
        Response.Flush(); 
        Response.End();
    }
Posted
Updated 5-Feb-12 20:56pm
v2
Comments
Sanjay K. Gupta 6-Feb-12 2:56am    
What this means
Actual name:REKHA MEHTA
Given result in excel:REKHA MEHTA

1 solution

Check the link [Here]
 
Share this answer
 
v3

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