gridview to excel problems RRS feed

  • Question

  • User-1204224568 posted



    I am exporting a gridview  to excel.

    evrything works fine but for one column which conatins customer number has 16 digit numbers in it and only 15 digits show up in excel and last digit is 0 for everyone.


    I tried using this code but would not work . please show me the coreect way to do it.


    Dim style As String = "<style> .text { mso-number-format:\@; } </style> "


    Protected Sub gvcustomers_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Cells(6).Attributes.Add("class", "text")

            End If



    Thanks in advance 




    Tuesday, April 29, 2008 12:41 PM

All replies

  • User1485238302 posted

    This is what I do: 

            foreach (GridViewRow r in gridViewMaster.Rows)
                if (r.RowType == DataControlRowType.DataRow)
                    for (int columnIndex = 0; columnIndex < r.Cells.Count; columnIndex++)
                        r.Cells[columnIndex].Attributes.Add("class", "text");                    
            string style = @"&lt;style> .text { mso-number-format:\@; } </style> ";
    Tuesday, April 29, 2008 4:06 PM
  • User691793677 posted

    I am also having the same problem.

    please find my code:

     Response.ContentType = "application/vnd.ms-excel";
                    // Remove the charset from the Content-Type header.
                    Response.Charset = "";
                    // Turn off the view state.
                    this.EnableViewState = false;

                    StringBuilder SB = new StringBuilder();
                    StringWriter tw = new StringWriter(SB);
                    HtmlTextWriter hw = new HtmlTextWriter(tw);


    please tell me what changes i need to make in code  so that export 16 digit number from datagrid to excel wprks perfectly. it will export 15 digits and replace 0 for 16 digit.

     please reply as soon as possible.


    Friday, August 8, 2008 10:11 PM