Skip to content
Tools— browse docs
On this page

Step 5: Paste from a spreadsheet

Optional, if you've got a minute: real sheets get filled by pasting, not typing.

One more, if you've got a minute — real sheets get filled by pasting, not typing. A block copied from Google Sheets or Excel is tab-separated columns, one row per line. Catch the paste, split it, and push every line on as a row:

const onPaste = (e: ReactClipboardEvent<HTMLDivElement>) => {
  const text = e.clipboardData.getData("text/plain")
  if (!text.includes("\t")) return
  e.preventDefault()
  const pasted = text
    .trim()
    .split("\n")
    .map((line) => {
      const [item, quantity, price] = line.split("\t")
      return { item: item ?? "", quantity: Number(quantity) || 0, price: Number(price) || 0 }
    })
  actions.list("rows").push(...pasted)
}
Paste a whole block
src/codec.ts + src/tool.tsx Lines 46 to 60 and 63 highlighted.

Edit and the example re-runs. Tab indents; press Escape to leave the editor.

Running · your edits, live
Starting the example…

You should see: select a few rows in an actual spreadsheet, copy them, click anywhere in the table above, and paste. Each line becomes a new row — no typing required.

Next steps