Recipe · Docling → spreadsheet
Docling to Excel: The Four Routes, and Which One Holds Up
Docling does not export .xlsx. It exports structure — and structure is what a spreadsheet needs, so the gap is a script rather than an impossibility. Here is how to close it without losing the numbers on the way.
Updated 2026-10-26 · 3 min read
The short version
- –Docling's table objects convert to data frames directly (
export_to_dataframe); that is the clean route. - –Do not round-trip through Markdown if you need numbers as numbers — it is lossy in exactly the ways spreadsheets care about.
- –
--to jsongives you the full structure including cell-level provenance; convert from that when you need to prove where a value came from. - –Most broken exports are merged cells, two-row headers and multi-page tables — check those three before blaming the parser.
- –If the destination is a spreadsheet and the job is recurring, a converter with a preview beats a script you maintain alone.
What Docling actually gives you
A conversion produces a DoclingDocument containing typed items. Tables are TableItem objects with a cell grid, spans, and page provenance. That is already a spreadsheet waiting to be written — it just needs an exporter.
The four realistic routes, ordered by how much fidelity they preserve:
| Route | Fidelity | Effort | Use when |
|---|---|---|---|
Python: export_to_dataframe | Highest — cells, spans, one frame per table | One script | You own the pipeline |
--to json then your own writer | High — full structure + provenance | More code | You need audit trails per cell |
| Markdown tables → CSV | Medium — merged cells and headers flatten badly | Trivial | Quick look, not for money |
| Hosted converter | High, with a visual check | None | You need the file, not the pipeline |
Route 1: the data frame
Every table in the document is available on doc.tables, and each converts to a pandas DataFrame. This is the route to use by default:
from docling.document_converter import DocumentConverter
import pandas as pd
doc = DocumentConverter().convert("statement.pdf").document
with pd.ExcelWriter("statement.xlsx", engine="openpyxl") as writer:
for i, table in enumerate(doc.tables, start=1):
df = table.export_to_dataframe(doc=doc)
df.to_excel(writer, sheet_name=f"table_{i}", index=False)
print(f"{len(doc.tables)} tables written")If doc.tables is empty on a document that clearly contains tables, the problem is upstream: tables were not detected. Check OCR settings and table mode before touching the exporter.
Route 2: JSON, when you need provenance
--to json emits the full DoclingDocument: table cells with bounding boxes, page numbers, and the reading-order structure. It is more work and it is the only route that answers "which page and which cell did this number come from".
For financial documents, that answer is not a luxury. It is the difference between a spreadsheet you can defend and one you have to re-check by hand.
docling convert statement.pdf --to json --to md --output ./out
# the JSON contains, per table:
# - cell text
# - row/column span
# - bounding box on the page
# - page numberRoute 3: Markdown, and why it bites
Markdown is the default output and the easiest thing to pipe into a CSV writer. It is also lossy in precisely the places spreadsheets are unforgiving:
- Merged cells are flattened — a value spanning three columns becomes one column and silence.
- Two-row headers collapse into one, so "2024 / Q1 / Q2" turns into three columns with a missing parent.
- Numbers arrive as text.
1,450.00looks right and sums to zero. - Accounting negatives —
(2,300)— lose their meaning unless your importer knows the convention. - Multi-page tables come back as separate tables with repeated headers; joining them is your job, not the parser's.
Markdown is for reading. Data frames are for arithmetic. Choose by what happens to the number next.
Route 4: an interactive preview with pandas / openpyxl
If the requirement is "this PDF, as a spreadsheet, today", the script above with pandas and openpyxl gives you complete control over sheet naming, number formats, and validation checks.
You can also preview and export extracted tables directly in your browser using the the online converter with no local environment setup.
The script leaves cross-page table joining and reconciliation to the reviewer. Check repeated headers, units and totals against the PDF before combining rows.
The validation checklist
Whatever route you take, four checks decide whether you have data or decoration:
Row count
Compare data rows in the source table to rows in the frame. A short count means missed rows; a long count means split cells became extra rows.
Column alignment
Pick one row with a distinctive value and confirm it sits under the right header. One shifted column invalidates the whole table.
Numeric types
In pandas, df.dtypes should show numbers as numbers. If a column is object, your totals are strings.
Cross-foot
Add the rows and compare to the document's own total. This is the check that catches a single misread digit — and the only one that catches it cheaply.
What Docling will not do for you
It will not decide which of the fourteen tables on page 60 is the income statement. It will not reconcile a running balance. It will not tell you that the scanned page it parsed at 73% confidence should be re-shot.
Those are the differences between extraction and analysis. Docling is a good extractor. If your question is "did this borrower overdraw in March", the table is the input, not the answer — see bank statement analysis for what comes next.
Frequently asked questions
Can Docling export directly to Excel?+
Docling CLI produces JSON or Markdown. A native .xlsx with formulas, multi-page tables stitched back into one frame and cross-footed totals needs a paid pipeline on top of the free parse; the playground here hands back Markdown, Excel, DocTags and JSON from a single file.
How do I get tables out of Docling with pandas?+
Iterate doc.tables and call table.export_to_dataframe(doc=doc) on each TableItem, then write each frame to its own sheet with pandas.ExcelWriter.
Why are my Docling tables empty when exported?+
If doc.tables is empty, tables were not detected — usually OCR disabled on a scanned page, or fast table mode on a complex layout. Fix extraction before touching the exporter.
Does the exported Excel keep merged cells?+
A DataFrame cannot represent merged cells. Spans are preserved in the JSON structure, and the data frame fills the spanned region — which is usually what you want for arithmetic, but not identical to the original layout.
Can I convert several PDFs to one workbook?+
Yes — loop over files, convert each, and append frames to the same ExcelWriter. Keep a source column so a row can be traced back to its file and page.
Try it online
Run the same pipeline in the browser — no install, no uploads stored.
See the recorded run →Keep reading
- Extracting PDF tables
What has to survive conversion
- OCR table extraction
Pixels to rows
- CLI reference
--to json and friends
- Python API
DocumentConverter basics
- Bank statement analysis
What to compute once it is in Excel
- Why PDFs lose formatting
The underlying cause