Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How Can I remove   from my Excel file which is converted to CSV from a dataview... I want a blank in Excel instead

i am convert my gridview data to CSV but in excel when there is no data it is showing
how can i remove this and showing blank
Posted

 
Share this answer
 
Comments
16041984 9-Jan-13 8:37am    
i upload it properly but it is showing   instead of blank in excel
16041984 10-Jan-13 7:31am    
some column in my datagridview is blank so it take   from database...thats why it is showing   in excel how i remove that   from excel
C#
Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition",
         "attachment;filename=GridViewExport.csv");
        Response.Charset = "";
        Response.ContentType = "application/text";

        //GridSearchdetails.AllowPaging = false;
        //GridSearchdetails.DataBind();



        //now we want to write the columns headers of the table
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < GridView1.Columns.Count; k++)
        {
            //add separator
            sb.Append(GridView1.Columns[k].HeaderText + ',');
        }
        //append new line
        sb.Append("\r\n");
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            for (int k = 0; k < GridView1.Columns.Count; k++)
            {
                //add separator
                //sb.Append(GridView1.Rows[i].Cells[k].Text + ',');
                string abc = GridView1.Rows[i].Cells[k].Text;
                abc.Trim();
                if (abc == "&nbsp;")
                {
                    abc = "";
                }
                if (abc == "")
                {

                }
                sb.Append(abc + ',');
            }
            //append new line
            sb.Append("\r\n");
        }
        Response.Output.Write(sb.ToString());
        Response.Flush();
        Response.End();
 
Share this answer
 

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