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
| Prop | Type | Default | Description |
|---|---|---|---|
source (required) | ViewerSource | An .xlsx file: a URL, a File/Blob, or bytes. | |
className | string | ||
defaultSheet | string | number | Sheet to open first, by name or index. Default the first. | |
fileName | string | Name used for export files and the table label. | |
header | boolean | "auto" | Whether the first row names the columns. auto (default) guesses per sheet. | |
height | string | number | Height of the table area. Default 480. | |
maxBytes | number | Files 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