Click here to Skip to main content
15,891,900 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am exporting a table to the excel at c#.
There is a field which type is double. There are deciamal values at this field.
But when I export table to the excel, it converts the values to the date format.

For the value 4,5 , excel shows this value like 04.May.
I replaced values which contains "," with "." before sending to the excel. But that does not work. It shows the values at date format again.

How can I prevent this situation ?

Thanks for the replies in advance..
Posted
Comments
njammy 5-Nov-12 10:48am    
Are you explicitly exporting to XLS format or CSV?
no_-_namee 5-Nov-12 13:21pm    
I am exporting to the excel at CSV format..
njammy 5-Nov-12 14:05pm    
Can you post the sample csv content, or the line which is being incorrectly formatted, along with the headings(data types).

1 solution

Use Range.NumberFormat[^] property to change cell/range format.

For example:
C#
Excel.Range oRange = objSheet.get_Range("A:A",system.type.missing);
oRange.NumberFormat = "General";
//or
oRange.NumberFormat = "# ##0.00";

Note: You need to change it before saving data into MS Excel sheet.
 
Share this answer
 
Comments
no_-_namee 6-Nov-12 1:42am    
Thanks for the replies . I thought that it exported at CSV format because of the name similarity. But the object is written by anyone. There is a class which named CSVString .The columns are append by adding ";" between them. And for a row, every field of the row is read and appended to a stringBuilder before exported to the excel.

By the way , when I look to datatable at quickwatch before exporting it to the excel, the field records is seen like 4,5 as it should be. But excel reads the column which type is double, as datetime column.

Thanks for the reply..
Maciej Los 6-Nov-12 15:29pm    
What is Excel decimal and thousand separator? What is windows system decimal and thousand separator? Show me a function to export data to Excel.

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