Click here to Skip to main content
Sign Up to vote bad
good
See more: C#Excel
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 5 Nov '12 - 4:44

Comments
onenomi - 5 Nov '12 - 10:48
Are you explicitly exporting to XLS format or CSV?
no_-_namee - 5 Nov '12 - 13:21
I am exporting to the excel at CSV format..
onenomi - 5 Nov '12 - 14:05
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:
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.
  Permalink  
Comments
no_-_namee - 6 Nov '12 - 1:42
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:29
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 218
1 Ron Beyer 215
2 Aarti Meswania 190
3 Rohan Leuva 178
4 Mahesh Bailwal 160
0 Sergey Alexandrovich Kryukov 8,553
1 OriginalGriff 6,899
2 CPallini 3,648
3 Rohan Leuva 2,963
4 Maciej Los 2,308


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid