Exporting recordset into csv files: Leading zeros

Question: Exporting recordset into a csv file seems to remove the leading zeros.

Root cause: The leading zeros appear to be removed from a csv file when viewed via Excel.

If you open a CSV with values which contains leading zeros, the leading zeros will be trimmed automatically (because Excel defaults to a General format instead of Text format).

For example, below a csv file that was exported from Certify. (The Certify layout contains four variables; N1, N2, T1 and T2 where N1 and N2 are number variables while T1 and T2 are text variables).

 

When opened (by double clicking on the csv file) in Excel, the leading zeros are removed.


To prevent Excel from opening a csv into a general format (and instead use a text format):

-          Open excel on your PC
-          Go to the data tab
-          Go to the 'From Text'
-          Find your csv that you found above
-          This should open a wizard where there will be three steps
-          On the third step make sure you select the column that you want to be 'text' not 'general'

 

 

Reference: http://answers.microsoft.com/en-us/office/forum/office_2007-excel/leading-zeros-removed-from-csv-file/4440e01e-985f-4ca4-8700-70b2e0621dec

Below is the correct values shown in the Excel after using the above steps to open the csv file in Excel.