Skip to content

SheetReader

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

Install

INSTALL sheetreader FROM community;
LOAD sheetreader;

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 coerce_to_string Type BOOLEAN Mode Named Description Default: false Coerce all cells in column of type VARCHAR to string (i.e. VARCHAR).
Argument force_types Type BOOLEAN Mode Named Description Default: false Use types even if they are not compatible with types determined by first/second row.
Cells, that are not of the column type, are set to NULL or coerced to string, if option is set.
Argument has_header Type BOOLEAN Mode Named Description Default: false Force to treat first row as header row.
  • If successful, the cell contents are used for column names.
  • If set to false (which is the default), the extension will still try to treat the first row as header row.
    The difference is that it will not fail, if the first row is not usable.
Argument threads Type INTEGER Mode Named Description Number of threads to use, while parsing
Argument sheet_index Type INTEGER Mode Named Description Default: 1 Index of the sheet to read. Starts at 1.
Argument types Type VARCHAR[] Mode Named Description List of types for all columns
  • Types currently available:
    VARCHAR,BOOLEAN,DOUBLE, DATE.
  • Useful in combination with coerce_to_string and force_types.
Argument skip_rows Type INTEGER Mode Named Description Default: 0 Number of rows to skip
Argument sheet_name Type VARCHAR Mode Named Description Default: "" Name of the sheet to read.
Only either sheet_index or sheet_name can be set.
Returns

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

Signatures from Haybarn 1.5.5; 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 1.5.5.

Linux · x86-64Linux · ARM64macOS · IntelmacOS · Apple SiliconWASM · exception handlingWASM · MVPWASM · 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.