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:44am

Comments
onenomi - 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..
onenomi - 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:
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: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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 514
1 Ron Beyer 286
2 OriginalGriff 248
3 samadhan_kshirsagar 229
4 Tadit Dash 213
0 Sergey Alexandrovich Kryukov 7,017
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,010


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