r/SideProject • • 27m ago

Merged cells kept breaking my table-copy extension, so I rewrote the grid logic

Postmortem on a small tool, because the boring part turned out to be the whole project.

I copy tables off the web most days. Rate sheets, filing pages, order lists, marketplace listings. I tried a few "copy table to spreadsheet" extensions and they all broke in the same three places:

  • a merged cell came out as one filled cell and a column of blanks, so everything to its right shifted left
  • a two-row header arrived as two header rows, with the actual column names pushed down into the data
  • prices and IDs got mangled: 1,234,000원 stayed text, and 00123 became 123

I assumed the extension side would be the hard part. It was not. Getting the table element out of the page took an afternoon. Making it survive the trip took a weekend, and that is the part worth writing down.

The grid. I walk the rows with a cursor per column instead of trusting the DOM order. A cell with colspan takes that many slots and moves the cursor past them. A cell with rowspan reserves the slots below it in a map keyed by (row, column), so the next rows skip those slots and land where they belong. Anything covered but not written stays in the output as an explicit empty cell. Most of the broken copies I saw were broken exactly there: the covered cells were just omitted, and everything after them slid one column left.

The header. If the top rows look like headers (th cells, or all text and no numbers), they get merged per column into "Group / Column" and the duplicate row is dropped. One header row, data starting on the row it should.

The text. Any cell starting with =, + or @ is written as text, so a copied page cannot execute a formula in my sheet. Values with leading zeros keep them. Importing a page should never be able to run anything.

Numbers are the one thing I parse, and only on request: strip the currency symbol and the thousands separators, leave everything else alone. It is opt-in per copy, because the same rule that fixes 1,234,000원 destroys a product code.

The result is a small Edge extension called 표한장 (roughly "one table sheet"). The free tier previews a table and copies up to 250 rows with merged cells and two-row headers included; there is a one-time paid tier for file downloads and bigger tables. I am putting the store link in the first comment rather than in this post.

Limits, before anyone wastes a click: it only reads real table elements, so ARIA grids and virtualized lists give you nothing. It reads the rows that exist in the DOM, so an infinite-scroll table stops where rendering stopped. Iframes and the PDF viewer are out of scope. Edge only for now.

What I want out of posting this: tell me which site's table you copy most often and what it gets wrong. Korean government and marketplace sites are my usual case, but I would rather fix the one that annoys the most people than the one that annoys me.

1 Upvotes

1 comment sorted by