---
title: Query Excel Files with SQL, Every Sheet a Table | DuckLocal
description: "Run DuckDB SQL on Excel workbooks without Excel or a database. Every sheet of an .xlsx, .xls, .xlsb or .ods file becomes a table you can join with CSV and Parquet. Free and local."
image: https://ducklocal.app/og-image.jpg?v=2
language: en
---

# 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. The workbook is read, never changed.

## From a workbook to an answer

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.
3. **Keep the result.** Chart it, profile each column, or export the complete result to CSV or Parquet.

## Join sheets, workbooks and files

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

```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: integers `BIGINT`, mixed integers and decimals `DOUBLE`, dates `TIMESTAMP`, true/false `BOOLEAN`, anything mixed `VARCHAR`.

- 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 are read 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.

A worksheet stops at 1,048,576 rows. For anything bigger, use CSV or Parquet and query the file directly.

## Workbooks from the command line

`ducklocal schema` lists a workbook with its sheets, and `--stats` profiles the first sheet. To query sheets from a script or an AI agent, save them into a database in the app, then query that file:

```bash
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"
```

## 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.

**Can I export the result back to a spreadsheet?** Export any result to CSV, which every spreadsheet app opens, or to Parquet. 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. It is not a spreadsheet editor.

## Links

- [Download DuckLocal](https://github.com/JetSquirrel/DuckLocal/releases/latest)
- [Supported file formats](https://ducklocal.app/docs/data-sources#supported-file-formats)
- [Query CSV with SQL](https://ducklocal.app/use-cases/query-csv-with-sql/)
- [Query JSON with SQL](https://ducklocal.app/use-cases/query-json-with-sql/)
- [SQL for AI agents](https://ducklocal.app/use-cases/ai-agent-sql/)

Source: https://ducklocal.app/use-cases/query-excel-with-sql/
