Maintain leading zeros in csv
-
- NewLounger
- Posts: 23
- Joined: 07 Jun 2010, 16:18
Maintain leading zeros in csv
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.
-
- Administrator
- Posts: 78631
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Maintain leading zeros in csv
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.
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
Hans
-
- NewLounger
- Posts: 23
- Joined: 07 Jun 2010, 16:18
Re: Maintain leading zeros in csv
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.
Again, you answered my question in a timely manner. Much appreciated.