Skip to content

SheetReader

Read Excel workbooks as SQL tables. Choose a worksheet, handle header rows, and control column types.

Install in Haybarn 2.0.0

INSTALL sheetreader FROM community;
LOAD sheetreader FROM community;

Arguments & returns

sheetreader

Table function
Signature
sheetreader( col0: VARCHAR, coerce_to_string := BOOLEAN = false, force_types := BOOLEAN = false, has_header := BOOLEAN = false, sheet_index := INTEGER = 1, sheet_name := VARCHAR = "", skip_rows := INTEGER = 0, threads := INTEGER, types := VARCHAR[] ) →
Arguments
Argument col0 Type VARCHAR Mode Positional Description Path to the Excel workbook.
Argument sheet_name Type VARCHAR Mode Named Description Default: "" Name of the worksheet to read. Cannot be combined with sheet_index.
Argument sheet_index Type INTEGER Mode Named Description Default: 1 Index of the worksheet to read (starting at 1). Cannot be combined with sheet_name.
Argument threads Type INTEGER Mode Named Description Number of threads used for parallel parsing.
Argument skip_rows Type INTEGER Mode Named Description Default: 0 Number of rows to skip before reading.
Argument has_header Type BOOLEAN Mode Named Description Default: false Require the first row to be usable as column headers. When false, SheetReader still attempts to use the first row as headers but does not fail if it cannot.
Argument types Type VARCHAR[] Mode Named Description Column types (VARCHAR, BOOLEAN, DOUBLE, DATE), one per column.
Argument force_types Type BOOLEAN Mode Named Description Default: false Enforce specified types even if they conflict with inferred types; incompatible cells become NULL or are converted to strings when coerce_to_string is set.
Argument coerce_to_string Type BOOLEAN Mode Named Description Default: false Coerce cells in VARCHAR columns to strings.
Returns

Dynamic schema. The output columns are determined at bind time and vary per call, so they aren't listed here.

Signatures from Haybarn 2.0.0; explanations from the developer documentation.

Query an Excel workbook

Download the sample workbook into your working directory. Its Sales worksheet contains product revenue that you can group with SQL.

SELECT product, sum(revenue) AS revenue
FROM sheetreader('sales.xlsx', sheet_name = 'Sales', has_header = true)
GROUP BY product
ORDER BY revenue DESC;

Output

product revenue
Coffee 540
Tea 180

This build requires XLSX text cells to use shared strings. Inline string cells are not supported.

Choose how the workbook is read

CREATE TABLE my_data AS 
FROM sheetreader(
    'data.xlsx',
    sheet_index=1,        -- or sheet_name='Sales'
    threads=8,            -- parallel parsing
    has_header=TRUE,      -- specify header presence
    skip_rows=0,          -- skip empty rows at top
    coerce_to_string=TRUE -- force columns to VARCHAR
);

Example from SheetReader’s documentation. Replace data.xlsx with your workbook.

Available in Haybarn

This reference uses the published build for Haybarn 2.0.0.

Linux · x86-64Linux · ARM64macOS · Apple SiliconWASM · exception handlingWASM · threadsWindows · x86-64

The example above is checked with native Haybarn. A WASM binary is published; this page does not yet offer a verified browser example.