Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 at 5-Nov-12 10:48am
   
Are you explicitly exporting to XLS format or CSV?
no_-_namee at 5-Nov-12 13:21pm
   
I am exporting to the excel at CSV format..
onenomi at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100