Share via


How to allow leading zero on export to csv

Question

Monday, July 1, 2013 1:56 PM | 1 vote

Hi,

We are having repeater control in our aspx page on click of button we are exporting all the repeater control data to csv file. Issue is if I enter 0012 in the repeater control and do export to csv and open the csv file it will not show leading  zeros in csv file it will display 12. Please let me know how to change the Number format to text programmatically on export.

Using .NET 2.0 and C#

Thanks..

All replies (5)

Monday, July 1, 2013 2:11 PM

I guess you are opening the .csv-file in Excel? Specify the cell format as Text and you should be able to see the zeros. If you open it in Notepad, you should see that the zeros are actually there.

http://social.msdn.microsoft.com/Forums/en-US/1957cdbe-2ca8-4a29-8284-31348977046a/losting-leading-zero-in-csv


Monday, July 1, 2013 2:33 PM

There are two possible issues:

1. The non-notepad programm you try to read the CSV with omits leading Zeroes.

2. You parse 0012 to a Integer before you save it.

Open the CSV in a Texteditor (like Notepad). And if the issue persists there, show us your code.

Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2


Wednesday, July 31, 2013 1:29 PM

Hi,

I need to change the csv Number format to "Text" from c# code. I will do Export To CSV and save to desktop. When I open csv file by default number format should be "Text" instead of "General".

Please let me know if this can be possible from c# to csv.

Thanks....... 


Wednesday, July 31, 2013 7:40 PM

I think you have a different problem then you think: You need to stop and learn the difference between Storage and Display.

Rule1: Never let display declare anything about storage

Rule2: Always use the most byte effcient way of storage possible, unless it is too costly from the point of CPU load.

The setting of the Celltype cannot be saved in CSV. It is pure storage format without any formating. Only table document formats can store things like Celltype (.xls, .xlsx, OpenTable Format).
There is simply no way to store "how you want to dispaly" any specific Column in a CSV. Once you have it open you can temporarily order a specific display but CSV cannot save that display.

Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.


Thursday, August 1, 2013 8:09 AM

Thanks for your reply.

I can conclude from the above statements that from C# code we can't handle csv number format but it can be handled from C# if file format is (.xls, .xlsx, OpenTable).