How to export a table with merged cells to CSV

Web tables use colspan and rowspan to merge cells. A CSV file cannot do that: every row has the same number of columns. A plain copy-and-paste often shifts the values after a merged cell one column to the left, so the data ends up under the wrong heading.

The rule to follow

When a cell spans several columns or rows, put its value in the first position and fill the other positions it covers, so every row has the same width. Some tools leave the covered positions empty and some repeat the value. Repeating is safer for sorting and filtering.

By hand

  1. Paste into a spreadsheet.
  2. Unmerge any merged cells.
  3. Fill the blanks down with a helper column: =IF(A3="",A2,A3).
  4. Paste the values back and save as CSV.

With an extension

Table to CSV & Excel – Table Copier reads the merged cells and expands them for you, so each row keeps its columns. Pick the table in the popup and choose Copy or Download. See the help page.

Check

Open the file in a text editor and count the commas in a few lines. Each line should have the same number.

Related: How to export an HTML table to a CSV file.