-
January 13th, 2010, 05:08 AM
#1
export datatable to Excel
Hello,
I'm currently working on exporting a datatable to an Excel file and I'm having some formatting problems.
The to export as a CSV would be absolutely fine, but when I download it and try and open it, Excel treats one of the ID columns as a number field (e.g. number is 016542, but excel opens it as 16542). I've tried putting each field in quotes but that hasn't made any difference. It works correctly if you view the CSV in notepad, but not by the time it opens in excel.
Is there any way I can add formatting to the cell, so it opens as a string? Failing that, how can I export it as an XLS file and add formatting that way?
Any ideas appreciated. Thanks
-
January 13th, 2010, 05:38 AM
#2
Re: export datatable to Excel
Fact 1)
If you want to create a Excel file, you have to create a real Excel file with C# and the Office assemblies.
There you can format all cells as you like. Search Google for "create excel file c#"
Fact 2)
If you create a CSV, you cannot open it directly in Excel in that way, that the data is inserted into the cells automatically.
You need to extra import the data in Excel by the menu "Data | Import external data....".
-
January 13th, 2010, 08:41 AM
#3
Re: export datatable to Excel
Hi MNovy. Thanks for your reply. I thought that was with the case for Fact 2, but was worth asking.
Found a great solution after searching Create Excel File. I'd been searching for Export to Excel which doesn't return nearly as good results.
Anyway, for other who may encounter this, I was able to use this code almost entirely and it worked a treat.
http://social.msdn.microsoft.com/For...c-c38493c0a664
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|