---
name: rescue-a-csv-import
description: "Recover the records from a broken CSV or delimited export: detect the delimiter and encoding, respect quoted fields, keep IDs as text, read amounts with the right decimal separator and list ragged rows. Use when a CSV opens in the wrong columns, loses leading zeros or splits rows."
license: CC-BY-4.0
metadata:
  author: Raq.com
  version: "2026-11-22"
  homepage: https://skills.raq.com/skills/rescue-a-csv-import
---

# Rescue a CSV import

Recover the intended records in a delimited export while preserving identifiers, decimal separators and punctuation inside quoted fields.

## When to use this skill

- A CSV opened in Excel or another tool shows everything in one column, split rows or shifted columns.
- An export from another country uses semicolons and decimal commas.
- IDs have lost leading zeros, or long numbers have turned into scientific notation after import.

## When not to use it

- Cleaning values once rows and columns are right, such as dates and missing markers. Use the clean a spreadsheet skill.
- Repairing a corrupt Excel workbook (.xlsx). This skill is for delimited text files.

## What you need

- The source file or raw sample, encoding or byte-order evidence if available, and the intended columns.
- The export locale and columns that hold identifiers, amounts and free text.

## Ask before you start

If any of these are missing or unclear, ask before doing the work.

- Can you share the original file, or its first rows exactly as exported, rather than a copy opened and saved in a spreadsheet? Re-saving may already have changed values.
- Which system and country produced the export? That suggests the delimiter, decimal separator and encoding.
- Which columns are identifiers, amounts and free text?

## Method

1. Read the original bytes where available. Honour a confirmed encoding and remove one leading byte-order mark from the first header only. If a pasted sample is already decoded, leave its encoding undetermined.
2. Try candidate delimiters outside quotes and check that the field count is consistent throughout the sample. Parse doubled double quotes and quoted line breaks as part of one field.
3. Count records with a CSV parser, not by lines. A quoted field can contain the delimiter or a line break, so physical lines and records differ.
4. Map the declared columns. Keep identifiers as text. Apply the source decimal and grouping conventions to amount columns only. Ask about contradictory separators rather than guessing a locale.
5. Verify the recovered row count, field widths and at least one identifier and amount against the source. Report each ragged record individually by its one-based data-record number, and do not repair it silently.
6. Give import settings that reproduce the result: delimiter, quote character, encoding, and which columns to set as text before loading, for example through Excel's From Text/CSV import.

## Checks before you deliver

- A BOM can look like part of the first column name. Stripping the start of every cell corrupts legitimate text.
- Counting commas by line breaks a quoted description and can split one logical record into several.
- Opening a CSV directly in a spreadsheet strips leading zeros and can turn long numbers into scientific notation. Set those columns to text during import.
- Applying a decimal-comma rule to every column changes identifiers and text that contain commas or full stops.

## How to present the result

Lead with the settings that read the file correctly: delimiter, quote handling, encoding and column types. Then show the recovered columns and the records checked against the source, and list any rejected records by number with the reason. Give the recovered row count so the person can confirm nothing was lost.

## Worked example

**Request:** Recover the records. The export uses German numbers, with sku as text and price as an amount.

**Supplied material:**

```text
﻿sku;price;description
00021;299,00;"Rack; narrow"
00034;12,50;Lamp
```

**Answer:** Import with a semicolon delimiter and double-quote handling. Set sku to text and price to a German-locale number. The two records are 00021 at 299 with description “Rack; narrow”, and 00034 at 12.50 with description “Lamp”.

## Structured output for tests

For an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.

Return delimiter as its literal character, columns as text in source order, rows as arrays of strings except declared amounts as JSON numbers, and rejected as one-based data-record numbers of records with the wrong field count.

## Sources

- [RFC 4180: CSV record and field syntax](https://www.rfc-editor.org/rfc/rfc4180.html#section-2): An Informational RFC rather than a formal standard. Section 2 says fields containing commas, double quotes or line breaks should be enclosed in double quotes, that a double quote inside a field is escaped by doubling it, and that each line should contain the same number of fields.
- [Microsoft Power Query: data types](https://learn.microsoft.com/en-us/power-query/data-types): For Excel, CSV and text files Power Query detects column types automatically from the first 200 rows, and it interprets dates and numbers using the locale. Microsoft's example shows UK day/month dates failing under a US locale until the column is converted with the right locale.
- [Microsoft Excel: keeping leading zeros and large numbers](https://support.microsoft.com/en-us/office/keeping-leading-zeros-and-large-numbers-1bf7b935-36e1-4985-842f-5dfa51f85fe7): Microsoft says Excel automatically removes leading zeros, shows large numbers in scientific notation and keeps only 15 digits, and recommends setting such columns to text when importing through From Text/CSV.

Test cases and an answer checker for this skill: https://skills.raq.com/skills/rescue-a-csv-import
