Broken CSV Repair

For the spreadsheet file that will not open — a CSV whose rows have gone out of step because of a stray quote or a comma in the wrong place. Every other tool needs a file that already reads properly; this one tells you which line is broken and why, then writes a clean copy.

How to use it

Nothing has to be mended by hand first: the file is read a character at a time, and when something is wrong the line, the position and what was found are noted while the reading carries on to the end.

  1. Paste the file exactly as it is Do not tidy it first. The stray quotes and odd line breaks are the evidence, and pasting through something that cleans them up hides the fault.
  2. Check the separator it chose It tries a comma, a semicolon, a tab and a vertical bar, and keeps whichever gives the most rows with a matching number of fields. If your file has one enormous column, the choice is wrong — set it by hand.
  3. Read the problem list Each entry gives the line number and a snippet, so you can go back to the source and see what produced it.
Full instructions

The file that will not open

paste it exactly as it is, formatting and all

What is wrong, and the fix

In depth

Fixing a CSV file that your spreadsheet refuses to open

A broken CSV is one of the most frustrating problems in everyday data work. The file looks fine when you open it in a text editor, but the spreadsheet scrambles the columns, loses rows, or simply refuses to load it at all. This article explains the four faults that break most files, walks through every control on the repair tool, and shows how to turn a damaged export into a clean file that any program will accept.

Screenshot: Reading the file everything else rejects
Reading the file everything else rejects as it appears when the page opens.

The four things that break CSV files

Nearly every broken CSV comes down to one of four problems. The wrong separator is by far the most common. A file exported in France or Germany typically uses semicolons because the comma is already the decimal point. Open that file in a program expecting commas and every row appears as a single giant column.

The second fault is unescaped quotes. The CSV rule is simple: if a value contains a quote mark, that quote must be doubled, and the whole value must be wrapped in quotes. Software that fails to do this produces a line the reader cannot parse, because it cannot tell whether a quote is ending a value or sitting inside one. A single badly quoted line can scramble every row that follows it.

The third problem is rows with the wrong number of fields. Some rows have too few, usually because trailing empty columns were dropped. Some have too many, usually because a value contained the separator and was never quoted. The fourth is line breaks inside a value, such as a street address that spans two lines. That is perfectly legal when the value is quoted, but unquoted line breaks split one row into two.

Pasting the broken file

The input area is labeled The file that will not open, and the hint says to paste it exactly as it is. That last part matters. Do not tidy the file first. Do not open it in another program to clean it up. The stray quotes, the odd separators, and the unexpected line breaks are the evidence. Removing them before the repair tool sees the file hides the fault.

You can also click Open a file to load the file from disk, or press Try an example to see a deliberately broken sample. The Clear button empties both panels.

Choosing the separator

The Fields are separated by dropdown defaults to Work it out. In that mode the tool tries a comma, a semicolon, a tab, and a vertical bar, and keeps whichever gives the most rows with a consistent field count. If your file shows up as one enormous column, the automatic choice was wrong and you should set the separator by hand.

The single biggest clue is the origin of the file. If it came from a system in continental Europe, try the semicolon. If it came from a database export, try the tab. If it was exported from a Unix pipeline, try the vertical bar. Once the separator is right, the columns fall into place and the real problems become visible.

Handling rows with the wrong field count

The dropdown labeled Rows with the wrong number of fields offers four strategies. Fill the missing ones with blanks pads short rows so they have the same number of columns as the header. This is the safest default because no data is discarded. Add columns for the extra ones widens the table so the extra values have somewhere to go. Drop the extra ones trims long rows back to the expected width. Leave them alone and just report does nothing except list the rows so you can inspect them yourself.

Short rows are usually harmless. They typically mean the exporting system omitted trailing empty fields. Long rows are more serious. A row with extra fields usually means a value contained the separator character and was not quoted. Before accepting the automatic fix for a long row, look at the original line. The extra field is often a comma inside a company name or an address.

The output controls

The Write the clean copy with dropdown lets you pick the separator for the repaired file. The choices are a comma, a semicolon, and a tab. Pick whichever the receiving program expects.

Two checkboxes sit below. The first, Add the mark that makes a spreadsheet read accents, is on by default. It adds a byte-order mark at the start of the file. Those three bytes tell Excel and other spreadsheets that the file is encoded in UTF-8, so names with accents, umlauts, or non-Latin characters display correctly instead of turning into nonsense. Leave it on unless you know the receiving system dislikes the mark.

The second checkbox, Trim spaces from the ends of every value, is off by default. Turning it on strips leading and trailing whitespace from every cell. This is useful when the export padded values to a fixed width, but leave it off if trailing spaces might be meaningful in your data.

The checkbox labeled The first line holds the column names tells the repair tool whether the first row is a header. When it is on, the header row is used to determine the expected field count and is not treated as data.

Reading the problem list

The right-hand panel, titled What is wrong, and the fix, shows two things. At the top is a list of every problem found, with the line number and a snippet of the offending content. Below that is the clean copy of the file, ready to copy or download.

Each problem entry tells you exactly what went wrong. A line about an unescaped quote gives you the position within the line where the parser lost track. A line about a ragged row tells you how many fields it has versus how many were expected. Reading these entries from top to bottom tells the story of the file: where it was fine, where it broke, and whether the break was a one-off or a pattern.

When you see thousands of broken rows starting from a particular point, look at the line just before that point. A single unescaped quote can throw the parser out of alignment for the rest of the file, producing a cascade of errors that all trace back to one line.

A worked example with a European export

Suppose you receive a file from a German system. You paste it in and the profiler shows one column with hundreds of characters per row. The automatic separator detection chose the comma, but the file actually uses semicolons because German numbers use commas as decimal separators. You change the dropdown to A semicolon, and the columns separate correctly.

Now the problem list shows three rows with six fields instead of the expected five. Looking at the snippets, each long row has an address field containing a semicolon that was never quoted. The tool has split that address across two columns. You set the ragged-row strategy to Leave them alone and just report, go back to the source system, fix the export, and run it again. This time the file is clean.

You set the output separator to a comma, leave the accent mark on, and download the result. The file opens perfectly in a spreadsheet on your machine.

Common mistakes when repairing

The most common mistake is accepting the clean copy without reading the problem list. The repair tool does its best, but a row where a value contained the separator cannot always be fixed automatically. If an address had a comma in it and the value was never quoted, the tool cannot know which comma was the separator and which was part of the address. It guesses, and sometimes the guess is wrong. The problem list shows you which rows were affected so you can check them.

Another mistake is trimming spaces when they matter. Some systems use fixed-width fields padded with spaces. Trimming is correct in that case. But if a field genuinely contains a space at the end, trimming it changes the data. When in doubt, leave the trim box off and handle spacing in the program that receives the file.

When repair is not enough

If a file has two different separators in it, perhaps because two exports were pasted together, the repair tool picks whichever separator explains the majority of rows and flags the rest. The honest answer is that the file needs to be split into two pieces and each one handled separately. The problem list makes that easy because it shows which rows disagree.

Files that are not CSV at all, such as fixed-width text or XML that was given a .csv extension, cannot be repaired into valid CSV. If the tool reports that every row has a different number of fields and no separator makes sense, the file is probably not a delimited format in the first place.

Privacy and where the processing happens

The file is read and rewritten entirely in your browser. Nothing is uploaded to a server. This matters especially for broken files, which may contain data you have not yet inspected and do not want leaving your machine. The clean copy is assembled locally and downloaded directly to your computer.

Help

Reading the file everything else rejects

Nothing has to be mended by hand first: the file is read a character at a time, and when something is wrong the line, the position and what was found are noted while the reading carries on to the end. You come away with a list of every problem, a count of the rows affected, and a clean copy quoted properly so the next program will open it.

Paste the file exactly as it is

Do not tidy it first. The stray quotes and odd line breaks are the evidence, and pasting through something that cleans them up hides the fault.

Check the separator it chose

It tries a comma, a semicolon, a tab and a vertical bar, and keeps whichever gives the most rows with a matching number of fields. If your file has one enormous column, the choice is wrong — set it by hand.

Read the problem list

Each entry gives the line number and a snippet, so you can go back to the source and see what produced it.

Take the clean copy

Values are quoted where they need to be, quotes inside values are doubled, and every line ends the same way.

One rule breaks more files than everything else combined

If a value contains a quote mark, that quote has to be written twice, and the whole value has to be wrapped in quotes. So a comment reading He said "hi" must be written as "He said ""hi""". Software that simply wraps the value and leaves the inner quotes alone produces "He said "hi"", and from that point on the reader has no idea whether it is inside a value or outside one — which is why a single bad line can scramble the entire rest of the file rather than just its own row. When you see thousands of broken rows starting at a particular point, look at the line just above that point.

Good to know

One enormous column means the wrong separator

It is the single most common symptom. A file exported in much of Europe uses semicolons because the comma is already the decimal point.

A value may contain a line break

An address field often does. That is perfectly legal as long as the value is wrapped in quotes, and this keeps those together rather than splitting the row.

Short rows and long rows mean different things

A row missing fields at the end is usually harmless and gets padded. A row with too many is a warning that a value contained the separator and was never quoted, so look at that line before you accept the fix.

The mark at the start is not rubbish

Those three odd bytes tell a spreadsheet the file holds accented letters. Without them, names come out as nonsense, so the clean copy puts one back.

Common questions

Why will my CSV not open properly?
Nearly always one of four things: the wrong separator, a quote that was not doubled, a value containing a line break, or rows with a different number of fields. All four are found and named here.
What does RFC 4180 mean?
It is the short document that describes how a CSV file should be written. The clean copy follows it, which is why other programs will accept it.
Will I lose any data?
Nothing is deleted unless you choose to drop extra fields. Padding adds blanks, widening adds columns, and both keep every value you started with.
Can it fix a file with two different separators in it?
It will pick the one that explains most of the file and report the lines that disagree. Genuinely mixed files need splitting into two, which the problem list makes easy.
Is the file uploaded?
No. It is read and rewritten in your browser.