Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

CSV file truncating 0's on left

I have an excel spreadsheet. In the first column I have numbers with padded 0's, in another column I have the last 4 of the SSN:

025
026
099
100

When I save the file as a CSV file, it is removing my padded zeros:

25
26
99
100

I want to retain the 0's and have it NOT remove the 0's for both columns. How do I do that?

thanks!
SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk

ASKER

I am using this spreadsheet for an import. It is importing without the leading zeros.

I want those columns saved as text. No one will be opening it. It will be uploaded to a website, and the website will open it and import the data.
How's the file originated, how are you importing it, and do you have the leading zeros if you open the csv in notepad before opening in excel.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bob, thanks for giving me points in your closing, but I respectfully disagree.
CSV files do not by default wipe out leading zeroes. A csv file opened in excel with default settings will not have any leading zeroes, yes, but the csv file is just a text file with commas (or semi-columns in some countries) separating the fields. Nothing in the .csv format entails the loss of the leading zeroes.
In my situation, saving an excel file as a CSV file does indeed truncate the leading zeros on the fields with numeric data.
Do you achieve your leading zeroes by way of a custom format, such as "0000"? If you do, that's why it doesn't transfer to csv since the underlying data does not have the leading zeroes, and only the display has them.

If you convert the numbers to text, for instance by using the formula =text(A1,"0000"), then it should save to csv with the leading zeroes (as long as you don't reopen it with excel).
Avatar of Rory Archibald
Thomas,
A csv will actually save using the displayed values, so a custom format will still work. I think your original hunch was correct.
Our clients are exporting text data to an Excel spreadsheet, then saving it as a CSV. They wont' be using formulaes because they already struggle with just that much.

In their database, the field is "0048" for SSN.

Then when they save it as a csv, it saves with "48" because it's dropped the leading zeros.

We've fixed this on the import by padding the data.
One final question on the subject, you say
Then when they save it as a csv, it saves with "48" because it's dropped the leading zeros.
How do you see that it saves as "48"? By opening the file in excel, or by opening it in notepad or another text editor?
what I want to do isn't possible.