scalpel@labs: ~/glossary/colspan-and-rowspan.mdx5 sections

Colspan and Rowspan: How Merged Table Cells Are Exported

colspan and rowspan let one table cell stretch across several columns or rows. On screen it reads fine, but a naive copy leaves holes where the covered cells would be. Filling every covered position with the merged value keeps the pasted grid rectangular.

extension: Scalpel Tablesupdated: 2026-08-14read_time: 2 min
less colspan-and-rowspan.mdx

Why it matters

A merged cell looks fine on the web. A header that spans three columns is centred and readable. But when you copy that table into a spreadsheet or plain text, the structure breaks. A naive copy leaves empty cells where the merged cell used to stretch, turning a neat grid into a lopsided one.

Scalpel Tables solves this by filling every covered cell with the merged value. So a header spanning three columns becomes three identical header cells in your export. The pasted grid is rectangular and usable.

How it works

The HTML attributes colspan and rowspan tell the browser: "draw this cell across N columns" or "across N rows." Internally, the browser builds an occupancy matrix: for each row, it walks left to right, placing each cell at the first free column, and marking the cells it covers.

When Scalpel exports a merged cell, it expands it: if a cell has colspan="3" and holds the text "Q1", the export writes "Q1" three times, once in each column the original spanned. Same with rowspan: a cell spanning two rows repeats in both. The result is a rectangular grid with no gaps, ready to paste into Excel or Google Sheets.

What does not matter

Diagonal or overlapping spans almost never occur in real tables, but when they do, Scalpel clamps the spans to the grid bounds. The output is always rectangular. And there is no such thing as a "half-span"; you have a full value or you do not.

Code example

Here is a table with a header that spans two columns:

<table>
  <tr>
    <th colspan="2">2026 Sales</th>
    <th>Region</th>
  </tr>
  <tr>
    <td>Q1</td>
    <td>Q2</td>
    <td>EMEA</td>
  </tr>
  <tr>
    <td>1,500</td>
    <td>2,100</td>
    <td>APAC</td>
  </tr>
</table>

On screen: the cell "2026 Sales" stretches across two columns, visually aligned above "Q1" and "Q2".

When Scalpel exports this, the header row becomes:

2026 Sales | 2026 Sales | Region
Q1         | Q2         | EMEA
1500       | 2100       | APAC

Every cell holds a value. The pasted grid is rectangular and ready for a pivot table.

How Scalpel shows it

Scalpel Tables displays a "spans" badge on any table card that holds colspan or rowspan. The expansion happens automatically; you copy the table and the rectangularised grid is already on the clipboard. The sticky preview under each table shows the expanded form, so you can check the layout before copying.

Sources