Click here to Skip to main content
15,920,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to to avoid exponential notation for a larger number while exporting gridview data to excel in asp,net with c#. I am using Visual Studio 2017. While I am exporting the gridview data one of the column value coming as 4567E+15 like this. I want it to be come as 4567243242424215 instead.

What I have tried:

My code is as below:
Response.Clear();

               Response.AddHeader("content-disposition", "attachment;  filename=" + strReportFileName + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");

               Response.Charset = "";
               Response.ContentType = "application/vnd.xls";

               System.IO.StringWriter stringWrite = new System.IO.StringWriter();

               System.Web.UI.HtmlTextWriter htmlWrite =
               new HtmlTextWriter(stringWrite);


                   grdDDASummary.RenderControl(htmlWrite);




               string strHead = strReportHeading + " FROM " + ViewState["FDOB"].ToString() + " TO " + ViewState["TDOB"].ToString();
               StringBuilder strbn = new StringBuilder();
               strbn.Append("<div style='text-align:center;font-weight:bold;background-color:White; width:100%;font-size:large'> " + strHead + "</div>");
               strbn.Append(stringWrite.ToString());

               Response.Write(strbn);
               Response.Flush();
               Response.End();
Posted
Updated 2-Sep-20 4:47am
Comments
Sandeep Mewara 2-Sep-20 9:42am    
It would be easier and not needed in code if the column in excel is marked as string instead of a number. That conversion is because of large number.

1 solution

You would have to add formatting information to the cell to get the result you want.

Do it yourself manually first. Open Excel and put the number you want to display in a cell and watch what happens. Format the cell to get the result you want. You'd have to add code to do the same thing in your app.
 
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