You must Sign In to post a response.
  • Category: ASP.NET

    Excel export leading zero problemi in c# from datatable

    I am using the following procedure to create an Excel spreadsheet from a DataTable:

    protected void UploadDataTableToExcel(DataTable dtEmp, string filename)
    string attachment = "attachment; filename=" + filename;
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/";
    string tab = string.Empty;
    foreach (DataColumn dtcol in dtEmp.Columns)
    Response.Write(tab + dtcol.ColumnName);
    tab = "\t";
    foreach (DataRow dr in dtEmp.Rows)
    tab = "";
    for (int j = 0; j < dtEmp.Columns.Count; j++)
    Response.Write(tab + Convert.ToString(dr[j]));
    tab = "\t";

    It works fine except when the cell only has numbers. For example:

    This "6969062201223401504" becomes "6.96902E+18"
    This "076854957" becomes "76854957"

    I would like the Excel spreadsheet to preserve every column as text, instead of converting them into integers
  • #763291

    Refer below link here they give some formats, may be this might be helpful to you, ""

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments