Maintain leading zeros in csv

Thalarcotos
NewLounger
Posts: 23
Joined: 07 Jun 2010, 16:18

Maintain leading zeros in csv

Post by Thalarcotos »

I know how to maintain the leading zeros in an xls file, but when I save the file as a csv, I lose the leading zeros. Anyway known? I've even tried using an ' before to no avail.

User avatar
HansV
Administrator
Posts: 78631
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Maintain leading zeros in csv

Post by HansV »

If you format a column as text or prefix values with an apostrophe, the values will be saved in the .csv file as entered, including leading zeros. You can check this by opening the .csv file in Notepad or another text editor. But if you open the .csv file in Excel, it'll try to be smart - it converts the values to (unformatted) numbers and so you lose the leading zeros.
If you want to preserve leading zeros even when opened in Excel, don't use .csv but .txt. You can specify how to treat columns when you open a .txt file in Excel.
Best wishes,
Hans

Thalarcotos
NewLounger
Posts: 23
Joined: 07 Jun 2010, 16:18

Re: Maintain leading zeros in csv

Post by Thalarcotos »

That explains why whenever I would reopened the .csv the leading zeros would be gone despite putting the ' before. I'll use the .txt format.

Again, you answered my question in a timely manner. Much appreciated.