0

I am generating the excel sheet but i am getting value exponential value in excel. please help how to format it as text or as original view like 2200202029393020 instead of 22002E+15

 HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.Headers.Add("X-Content-Type-Options", "nosniff");
    HttpContext.Current.Response.Charset = " ";
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Employee_Detail.xls;");
    HttpContext.Current.Response.Write("<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">");
    HttpContext.Current.Response.Write("<tr><td colspan=3 ><b><font size=6> Employee_Details</font></b></td></tr>");
    HttpContext.Current.Response.Write("</table>");
    HttpContext.Current.Response.Write("<table cellspacing=\"0\" cellpadding=\"2\" border=\"1\">");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td><b><font size=4> Name </font></b></td>");
    HttpContext.Current.Response.Write("<td><b><font size=4>Employee Id</font></b></td>");
    HttpContext.Current.Response.Write("<td><b><font size=4>Department</font></b></td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Ram</td>");
    HttpContext.Current.Response.Write("<td>2200202029393020</td>");
    HttpContext.Current.Response.Write("<td>Accounts</td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Jordan</td>");
    HttpContext.Current.Response.Write("<td>2200202029393021</td>");
    HttpContext.Current.Response.Write("<td>Sales</td>");
    HttpContext.Current.Response.Write("</tr>");


    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Shyam</td>");
    HttpContext.Current.Response.Write("<td>2200202029393022</td>");
    HttpContext.Current.Response.Write("<td>Production</td>");
    HttpContext.Current.Response.Write("</tr>");


    HttpContext.Current.Response.Write("<tr>");
    HttpContext.Current.Response.Write("<td>Donald</td>");
    HttpContext.Current.Response.Write("<td>2200202029393023</td>");
    HttpContext.Current.Response.Write("<td>HR</td>");
    HttpContext.Current.Response.Write("</tr>");

    HttpContext.Current.Response.Write("</table>");
    HttpContext.Current.Response.End();
    HttpContext.Current.Response.Flush();
leppie
  • 115,091
  • 17
  • 196
  • 297
RosiReddy
  • 27
  • 3
  • 14

1 Answers1

1

may be it's late, but this helps someone i think. because i spent too much time to find this solution .

You can add style to your "td" like that

"<td style='mso-number-format:\"\\@\";'>YOUR VALUE</td>"

or you can add zero width space character after your "td" like that

"<td>&#8203;YOUR VALUE</td>"

Format HTML table cell so that Excel formats as text?

best regards.

Community
  • 1
  • 1
Muzaffer Galata
  • 580
  • 1
  • 9
  • 22