📊 readExcel — XLSX file reading

tsb can read Excel XLSX files natively — no dependencies. The readExcel() function accepts a Uint8Array or ArrayBuffer and returns a DataFrame.

Python equivalent: pd.read_excel("data.xlsx")

Basic usage

import { readExcel, xlsxSheetNames } from "tsb";

// Read first sheet (default)
const df = readExcel(buffer);
console.log(df.shape);         // [rows, cols]
console.log(df.columns.toArray()); // column names

// List all sheet names
const sheets = xlsxSheetNames(buffer);
// → ["Sheet1", "Summary", "Data"]

// Read a specific sheet by name
const df2 = readExcel(buffer, { sheetName: "Summary" });

// Read a specific sheet by index
const df3 = readExcel(buffer, { sheetName: 1 });

Options

Option Type Default Description
sheetName string | number 0 Sheet to read (name or 0-based index)
header number | null 0 Row index of the header, or null for no header
indexCol string | number | null null Column to use as the row index
skipRows number 0 Data rows to skip after the header
nrows number unlimited Maximum number of data rows to read
naValues string[] [] Additional strings to treat as NA

Interactive demo

Upload an .xlsx file to inspect it, or use the demo data below.

or

     

Upload a file or click "Load demo data" to start.

Advanced example

// Use a named column as the row index
const df = readExcel(buffer, { indexCol: "ID" });

// Skip 2 rows and read at most 100 rows
const df2 = readExcel(buffer, { skipRows: 2, nrows: 100 });

// Treat custom strings as missing
const df3 = readExcel(buffer, { naValues: ["N/A", "MISSING", "-"] });

// DataFrame operations work immediately
df.describe();
df.col("revenue").sum();
df.groupby("region").mean();

Python equivalent

# pandas
import pandas as pd

df = pd.read_excel("data.xlsx", sheet_name=0)
df = pd.read_excel("data.xlsx", sheet_name="Summary")
df = pd.read_excel("data.xlsx", header=None)
df = pd.read_excel("data.xlsx", index_col="ID")
df = pd.read_excel("data.xlsx", skiprows=2, nrows=100)