SpreadsheetViewer

Open an Excel workbook (.xlsx) as tabs of tables, with the cells’ numbers, dates and booleans kept as types.

Status: beta. Category: Viewers.

import { SpreadsheetViewer } from '@glyphui/viewers/spreadsheet'

Exports: SpreadsheetViewer, spreadsheetViewerStyles.

Notes

  • Install the optional peer dependencies first: npm install read-excel-file @tanstack/react-table @tanstack/react-virtual.
  • It reads .xlsx files (Office Open XML). The old binary .xls format isn’t supported.
  • Merged cells show their value in the first cell and leave the rest blank.
  • Files over 20 MB ask before opening, since the whole workbook is read in memory; change it with maxBytes.

SpreadsheetViewer props

PropTypeDefaultDescription
source (required)ViewerSourceAn .xlsx file: a URL, a File/Blob, or bytes.
classNamestring
defaultSheetstring | numberSheet to open first, by name or index. Default the first.
fileNamestringName used for export files and the table label.
headerboolean | "auto"Whether the first row names the columns. auto (default) guesses per sheet.
heightstring | numberHeight of the table area. Default 480.
maxBytesnumberFiles larger than this ask before opening, since the whole workbook is read in memory. Default 20 MB.

Example: Two sheets

Switch sheets with the tabs; each has its own filters.

import { SpreadsheetViewer } from '@glyphui/viewers/spreadsheet'
import { fixture } from '../../../lib/fixtures'

export default function Example() {
  return <SpreadsheetViewer source={fixture('sales.xlsx')} height={420} className="w-full" />
}

Live page: https://glyphui.xyz/components/spreadsheet-viewer