NOTE: this question is almost a dupe of:
stop Ms Excel auto-formatting numeric strings as numbers
I say ‘almost’ because this specific question was not asked …
Question: Is there a way to attach a ‘schema’ to a CSV file, prior to Excel import, that allows Excel to understand the correct formatting of the CSV file without requiring post-processing of the CSV file and without requiring end-user intervention in order to correctly format the fields by hand?
By schema, I mean any method whatsoever of generating a text-based definition that can be saved somewhere on Customer X’s machine and then referenced whenever the usual CSV import has to take place, including but not limited to XSD, VBMacro, or whatever conventions Excel has for this kind of operation (if any).
Background: Excel has a habit of being ‘helpful’ by modifying input data when opened from plain-text such as a CSV file.
For an example of what is meant by this, see any of the various following links:
http://ask.metafilter.com/28449/Preventing-Excel-applying-time-formatting-to-imported-data http://excel.tips.net/Pages/T002588_Handling_Leading_Zeros_in_CSV_Files.html http://social.msdn.microsoft.com/Forums/en-US/isvvba/thread/aae07b39-865f-4c68-a07f-7cad2dfd6733 http://social.msdn.microsoft.com/forums/en-US/vsto/thread/80285088-b476-418f-9613-a2c499c8da7b/
We regularly have to send CSV files to customer X and we do not have the luxury of modifying the CSV files directly in order to ‘morph’ them into a format that Excel will render exactly as intended.
Moreover, customer X does not always have the personnel who are trained with Excel in order to do the import correctly.
What I’ve done when facing this problem is create a macro to run after the import which ‘un-fixes’ Excel’s fixes. It’s not a great solution, but it’s a working workaround.