From pixels to spreadsheet cells: how OCR table reconstruction and XLSX/CSV generation work
How bounding-box clustering aligns rows and columns, why merged headers challenge OCR engines, and how safe CSV quoting and XLSX packaging run locally in your browser.
Extracting plain paragraphs from a scanned letter is already tricky, but turning a photographed table into a clean spreadsheet is an order of magnitude harder. A spreadsheet does not only need the right letters and digits; it needs every number placed in the exact row and column where formulas expect it. Understanding how optical character recognition (OCR), coordinate clustering, and XLSX/CSV generation work insideDocument to Excel helps you get cleaner tables and fix edge cases in seconds.
1. Why tables break ordinary text-only OCR
A standard OCR engine reads left to right across a line of pixels and outputs words paired with bounding boxes (x, y, width, height). If you simply copy raw OCR lines into a spreadsheet, spaces collapse and columns drift out of alignment whenever a product description wraps onto two lines or a cell is intentionally blank.
To rebuild a true two-dimensional grid, Document to Excel groups recognized tokens by vertical baseline overlap to detect rows, then clusters horizontal X-intervals across those rows to infer column boundaries. Multi-page PDFs are rendered page by page through the browser Canvas pipeline before extraction so scanned PDF tables and raw camera photos share one consistent preprocessing step.
2. Local OCR vs AI Mode: architectural trade-offs
Inside the Extract dialog, you choose the extraction engine per document. Each path behaves differently on complex table layouts:
| Extraction path | Where processing runs | Strengths | Common failure modes to verify |
|---|---|---|---|
| OCR (On-device) | 100% in your browser via local WebAssembly | Zero file upload, works offline once loaded, predictable on sharp printed grids | Multi-line wrapped descriptions, merged header spans, or tilted mobile photos |
| AI Mode (Online, optional) | Sent only when you explicitly pick AI Mode | Better at dense receipts, multi-line rows, nested subtotals, and noisy camera angles | Requires network availability; always verify totals and decimal digits manually |
3. How the editable grid protects your spreadsheet data
Rather than dumping an opaque file straight to your Downloads folder, Document to Excel opens every extracted table inside an interactive grid beside the original document preview. That side-by-side layout exists for an engineering reason: automated extraction always carries small character uncertainty (such as 0 vs O,1 vs l, or comma vs period decimal separators).
- Direct keyboard editing and history: Every cell edit, row insertion, column deletion, copy, cut, and paste pushes onto a local undo/redo stack so structural fixes are reversible.
- Preserving leading zeros and codes: Product SKUs, postal codes, and phone numbers like
00412are stored as strings in the grid so they do not silently lose leading zeros while you edit. - Multiple worksheets for multi-page PDFs: Multi-page documents can organize tables into separate worksheet tabs before export so headers from page 2 do not collide with page 1 totals.
4. What happens when you export XLSX vs CSV
When you click Download, your browser builds the output file locally in memory without calling a server:
- XLSX export: Packages XML worksheet sheets, shared string values, and workbook metadata into a standard OpenXML ZIP archive readable by Microsoft Excel, LibreOffice Calc, and Google Sheets.
- CSV export: Serializes the active worksheet as UTF-8 text using RFC 4180 quoting rules. Any cell containing a comma, newline, or double quote is safely escaped so opening the CSV never shifts columns sideways.
- Formula injection hygiene: Unverified OCR strings starting with
=,+,-, or@can be interpreted as executable formulas in desktop spreadsheet apps. Always inspect flagged cells before sharing exported sheets with teammates.
For a practical post-extraction cleanup checklist covering dates and currency formats, readCleaning extracted tables for Excel and Google Sheets, or openDocument to Excel to try local table extraction now.