Avatar of E=mc2
E=mc2Flag for Canada

asked on 

How can I save an Excel spreadsheet to CSV and preserve the format?

Spreadsheet with 2 columns, A and B.

Column A contains Item numbers, many of which start with leading zeros.  ie 00001,  00002, etc...
When you save the Excel spreadsheet to CSV it removes the leading zeros and the numbers show up only as 1, 2 etc..  it must keep the leading zeros.
Microsoft Excel

Avatar of undefined
Last Comment
E=mc2
Avatar of Glenn M
Glenn M

CSV is typically just ASCII text so there's no way I'm aware of to preserve any formatting. Even if you format the cells in Excel as text when you save as CSV the leading zeros will get stripped out.
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

This is correct. CSV files will not save formatting, spacing, font, color, etc. In its simplest form it is data in plain text seperated by commas. If you want those options you need to keep it in xls or xlsx format.
Avatar of aikimark
aikimark
Flag of United States of America image

If you format the cells/columns as text, you should be able to output a CSV file with the leading zeros preserved.

See the attached CSV for an example
Q-28586471.csv
Avatar of Glenn M
Glenn M

That's true aikimark. We don't know what application the posted will be opening the CSV file in. I know in Excel it will treat it as a general format and strip the zeros.
Avatar of aikimark
aikimark
Flag of United States of America image

If saved with a .txt file extension, Excel might be inclined to treat the column as text, especially if it is quote delimited.
Avatar of Danny Child
Danny Child
Flag of United Kingdom of Great Britain and Northern Ireland image

If you can start your text with an ' (apostrophe) character, you can then add as many leading zeros as you want, and if saving to CSV, then the formatting should be preserved.

HOWEVER, if you open the CSV in Excel again, the formatting is lost - even with double-quotes " around them.

So, it seems to be a one-way trip.  Does this work for you?  Why do you need ad CSV, please? Where's the data going....?
Avatar of Ejgil Hedegaard
Ejgil Hedegaard
Flag of Denmark image

It is not a one way trip.
As alkimark says
Excel might be inclined to treat the column as text
If the csv file is imported to Excel using the data import wizard, you can define the column to be treated as text, and the leading zeros are preserved.
ASKER CERTIFIED SOLUTION
Avatar of E=mc2
E=mc2
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of E=mc2
E=mc2
Flag of Canada image

ASKER

This works.
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo