How to Stop Long Numeric to Scientific Conversion if Transfering data from DataGrid to Excel.

R

RSB

Hi Everyone,
i am using the following code to transfer a DataGrid to Excel File.
Every thing works ok beside the long numerice value like 0000121900000000
gets converted to 1.219E+11.
how can i disable that conversion?
Thanks for the Help

RSB



public static void DataGridToExcel(DataGrid dgExport, HttpResponse
response){
response.Clear();
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataGrid dg = new DataGrid();
dg = dgExport;
dg.AllowPaging = false;
dg.AllowSorting = false;
dg.GridLines = GridLines.Both;
dg.HeaderStyle.Font.Bold = true;
dg.DataBind();
dg.RenderControl(htmlWrite);
response.Write(stringWrite.ToString());
response.End();
}
 
D

David Jessee

Well, its not converting....its just a formatting issue. I don't know what
your class is doing as far as exporting the data, so I can't tell you
exactly how to do it. But approach it as a formatting issue
 
Joined
Jul 31, 2007
Messages
1
Reaction score
0
You should format your data in order to fake the excel that this value is not numeric. Normally in excel a leading ' character is enough to make the cell in text format ' character should not be seen in the grid.

So you should format the grid column as DataFormatString=" {0}"

I think this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top