Skip to content

Import a CSV file without losing zeros and dates

Clean up messy data8 min

Builds on Split a column with Text to Columns and Save, file types and AutoSave.

A purchasing analyst in Chicago gets a supplier's shipment file from Leipzig every Monday. Opened with a double-click, the postal codes lose their leading zero, the tracking numbers turn into 1.23457E+17, and 03/04/2027, meant as April 3, comes in as March 4.

How it works

A CSV file is plain text: one line per row, a comma or a semicolon between the fields, and no formats. Double-click one, and Excel reads each field as if you had typed it. A code like 04109 becomes the number 4109, a number longer than 15 digits keeps only its first 15 and shows in scientific notation, and a date is read in your computer's order, month first in the US.

Import it instead, and say how to read each column:

  • Data > From Text/CSV opens a preview where you check the Delimiter. Transform Data opens the file in Power Query, where you set each column's type, Text for codes and IDs, and Close & Load writes it to a sheet. On a Mac, choose Data > Get Data (Power Query), then Text/CSV.
  • The Text Import Wizard has the three steps of Text to Columns, plus the row to start at. Set Text for codes and Date in the file's order, such as DMY. On Windows, switch it on under File > Options > Data (Show legacy data import wizards), then choose Data > Get Data > Legacy Wizards > From Text (Legacy). On a Mac it's Data > From Text (Legacy).

In Microsoft 365, File > Options > Data > Automatic Data Conversion (Excel > Preferences > Edit on a Mac) can switch some of these conversions off.

Example

Two rows of the Leipzig file, opened with a double-click and imported with each column set:

Opened directly, Excel guesses each column and loses data on the way, and the two tracking numbers even end up the same. Imported, each column is read as you say, Text for codes and DMY for day-first dates.

Common mistakes

  • General for a column of codes. 04109 becomes 4109, and formatting the column afterward can't bring the zero back. Set the column to Text when you import.
  • A day-first file read in US order. 03/04/2027 comes in as March 4 and 13/04/2027 stays text. Pick Date with DMY.
  • Starting at row 1 when the file opens with lines about the export. Set Start import at row to the line that holds the headings.

In short

  • Double-clicking a CSV lets Excel guess each column, and it guesses codes and foreign dates wrong.
  • Import with Data > From Text/CSV or the Text Import Wizard, and set each column's type.

Practice

4 exercises · free, no account needed

Start practicing
  1. Not started

    1. Where the leading zeros went

    Quiz · easy

  2. Not started

    2. Import the warehouse's semicolon file

    Dialog · medium

  3. Not started

    3. Import a bank statement with lines on top

    Dialog · hard

  4. Not started

    4. Find the command that imports a CSV file

    Find it · easy