excelcsvformattingnumber-formatting

Excel CSV - Number cell format


I produce a report as an CSV file. When I try to open the file in Excel, it makes an assumption about the data type based on the contents of the cell, and reformats it accordingly.

For example, if the CSV file contains

...,005,...

Then Excel shows it as 5. Is there a way to override this and display 005?

I would prefer to do something to the file itself, so that the user could just double-click on the CSV file to open it.

I use Excel 2003.


Solution

  • There isn’t an easy way to control the formatting Excel applies when opening a .csv file. However listed below are three approaches that might help.

    My preference is the first option.

    Option 1 – Change the data in the file

    You could change the data in the .csv file as follows ...,=”005”,... This will be displayed in Excel as ...,005,...

    Excel will have kept the data as a formula, but copying the column and using paste special values will get rid of the formula but retain the formatting

    Option 2 – Format the data

    If it is simply a format issue and all your data in that column has a three digits length. Then open the data in Excel and then format the column containing the data with this custom format 000

    Option 3 – Change the file extension to .dif (Data interchange format)

    Change the file extension and use the file import wizard to control the formats. Files with a .dif extension are automatically opened by Excel when double clicked on.

    Step by step: