× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Re: Preserving leading zeros in a CSV

You didn't specifically say that you're opening the file with Excel,
but we can guess from your symptoms that's what you're doing.

The most direct answer is: No, there isn't any way to create a CSV
that preserves leading zeros using CPYTOIMPF. This is because CSVs
inherently do not store type information, and certainly not type
information that is honored by Excel. Excel aggressively tries to
interpret everything as a number if it can. And every number in Excel
is (roughly) a double-precision float, so it doesn't have enough
precision to store your "number" precisely, even after disregarding
the leading zeros.

There are kludges. If you can write a program to create the CSV, then
you have a few options at your disposal. The main thing, if you
absolutely must stick to CSV, and the file will be opened in Excel, is
to turn your data into a formula which evaluates to a string:

="00007292380143329052"

But a better option, if you can swing it, is to generate Excel files
(native Excel, either .xls or .xlsx) rather than CSVs. There are a
host of ways to do this, either with RPG or other programming
languages.

If you can't do the programming, and this is a one-time (or extremely
rare) task, then I recommend trying the import wizard, as suggested by
Matt.

John

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.