We all know Excel's annoying behavior of removing leading zeros from imported CSV files
I am a developer and I'd like to program an export feature that creates a CSV file that forces Excel to keep the leading zeros.
I hoped "012345" would result in 012345, but even then Excel 2010 strips the leading zero ;(
Naming the file *.txt instead of *.csv forces Excel to use the wizard as https://www.youtube.com/watch?v=9KDK1FRcmSo suggested. But I really doubt that the user knows how to operate the wizard. He must change the data type from "General" to "Text" at one of 30 columns. I believe the user will just click Next, Next, Finish.
Any better idea that avoids using the wizard?
Is there an official character to "mask" a zero while importing a CSV file into Excel? I've tried ' (Typewriter apostrophe). But it's not the same to enter '0123
in Excel compared to open a CSV with '0123
.
NBSP
. Experimentation suggests that thetab
(CHAR(9)
) as well as multiple other characters in the<32
code range (but not all) will also work. Or you could save it asUnicode text
and use the UnicodeZWSP
character.TAB
is most promising! I now have to double check that it doesn't cause harm at any other point.