Click here to Skip to main content
12,763,515 members (33,864 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# MS-Excel
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 5:44am
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

Rate this: bad
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";
oRange.NumberFormat = "# ##0.00";

Note: You need to change it before saving data into MS Excel sheet.
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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2017
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