Query Excel files with SQL

Open a workbook in DuckLocal and every sheet becomes a table. Join sheets to each other, to CSV and Parquet files, or to a DuckDB database, and get answers a pivot table can't. No Excel install, no database server, nothing uploaded.

Free and open source for macOS, Windows and Linux. Your workbook is read, never changed.

From a workbook to an answer

Drag the file in, or open it from the menu. There is no import wizard to click through.

  1. Open the workbook

    The first sheet becomes a table named after the file: budget.xlsx gives budget. Every other sheet is named {file}_{sheet}, such as budget_actuals. Empty sheets are skipped.

  2. Write SQL against the sheets

    The schema sidebar lists each sheet's columns and inferred types, and autocompletion knows them. Use joins, window functions, PIVOT and the rest of DuckDB SQL.

  3. Keep the result

    Chart it, look at each column's distribution, or export the complete result to CSV for a spreadsheet or Parquet for other tools.

Join sheets, workbooks and files

A lookup across sheets that would take VLOOKUP formulas is a single JOIN in SQL. The same works between two workbooks, or between a sheet and a CSV export from another system.

The SQL editor · Query CSV with SQL

-- budget.xlsx: first sheet → budget,
-- sheet "actuals" → budget_actuals
SELECT b.department,
       b.planned,
       sum(a.amount)             AS spent,
       b.planned - sum(a.amount) AS remaining
FROM budget b
JOIN budget_actuals a USING (department)
GROUP BY b.department, b.planned
ORDER BY remaining;

How a sheet becomes a table

The first row is the header. Each column gets the narrowest type that holds every cell in it. Integers become BIGINT, mixed integers and decimals DOUBLE, dates TIMESTAMP, and true/false values BOOLEAN. Anything mixed stays VARCHAR, so nothing is lost and you can TRY_CAST it in SQL.

Workbook import in detail

  • Empty cells become NULL
  • An empty header cell becomes column_1, column_2…
  • A repeated header gets a suffix: amount, amount_2
  • Formula results come through as values
  • The workbook file is never written to

A copy you can keep

Unlike CSV and Parquet, which DuckLocal reads in place, a sheet is copied into a table when you open the workbook. If you change the file in Excel, open it again and the tables are replaced.

To keep the tables, open a .duckdb database first and then the workbook. The sheets are saved into that database, ready the next time you open it, and readable by any DuckDB client.

Workbooks from the command line

ducklocal schema lists a workbook with its sheets, and --stats profiles the first sheet: nulls, distinct values, ranges and medians per column. An AI agent can see what a spreadsheet holds before it writes any SQL.

To query sheets from a script or an agent, save them into a database in the app as described above, then run ducklocal query --database on that file.

Read the CLI guide · SQL for AI agents

Terminal
$ ducklocal schema budget.xlsx
$ ducklocal schema budget.xlsx --stats
$ ducklocal query --database budget.duckdb \
  --sql "SELECT department, sum(amount)
         FROM budget_actuals
         GROUP BY department"

Excel and SQL questions

Which spreadsheet formats can DuckLocal query?
Excel .xlsx, .xls and .xlsb workbooks, and OpenDocument .ods spreadsheets. Every non-empty sheet is imported as its own table.
Does DuckLocal change my workbook?
No. It reads the file and copies each sheet into a table. The workbook itself is never written to. If you edit it in Excel afterwards, open it again to pick up the changes.
Do formulas come through?
The values do. DuckLocal reads the results your spreadsheet app saved in the file, not the formulas behind them, so a column of totals arrives as numbers.
Can I export the result back to a spreadsheet?
Export any result to CSV, which Excel and every other spreadsheet app opens, or to Parquet for other data tools. DuckLocal does not write .xlsx files.
Is DuckLocal an Excel alternative?
For analysis, yes: joins across sheets and files, aggregates, and data too large for a worksheet's 1,048,576-row limit. It is not a spreadsheet editor; you do not type into cells or write formulas.

Run SQL on your own workbook

Download DuckLocal, drop in a spreadsheet, and join its sheets in one query.