Click here to Skip to main content
11,575,923 members (57,246 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
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 9-Jan-13 0:38am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
16041984 at 9-Jan-13 8:37am
   
i upload it properly but it is showing   instead of blank in excel
16041984 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 350
1 Dave Kreskowiak 160
2 F-ES Sitecore 145
3 OriginalGriff 125
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100