Result: imported rows after opening a workbook whose first row is Item, Amount
The source file has headers Item, Amount, then rows Tea, 12 and Coffee, 18. The headers become column keys, not data cells. Edit a value, then save the current workbook.
The adapter initializes WASM after client mount and destroys its Grid on unmount. Use the handle published by onReady, not a handle captured before initialization. Import replaces the workbook and data together. This creates a new Grid generation; ready publishes its replacement. Do not call grid.destroy() on an adapter-owned Grid.
The adapter clears its exposed or bound handle before reset. The ready callback receives the new generation. Dispose any host subscriptions or persistence coordinators before attaching them to the replacement. This example attaches none. File controls are disabled during conversion, and unmount aborts the outstanding codec operation.
For SvelteKit, use a client-only route or create this component after client mount. Import the adapter stylesheet once. Keep workbook and data identities stable between imports so unrelated renders do not reset edits.
Options and limits
Choice
Behavior
Import
fromXlsxTable reads only the first sheet. Its first row supplies headers. Formula source and workbook formatting are not preserved by table import.
Save
toXlsxWorkbook saves the current Grid as a workbook, not only its visible viewport.
Budget
This example accepts 100,000 cells and at most 8 MiB of input. Codec defaults still bound ZIP entries, expanded bytes, XML depth and other resources.
Cancel
Unmount aborts work between bounded codec stages. Cancellation is not an immediate interrupt inside a stage.
Import builds the full result in memory. The Blob workbook importer avoids an initial full-file buffer, but still returns an in-memory snapshot; it is not an unbounded-data reader. Use workbook interchange instead of table import when you must retain sheets, formulas, styles and kept parts. Surface its onWarning messages when fidelity matters. Resource failures are XlsxResourceError values and also satisfy isSheetwriteError.
let input: {
workbook: Workbook;
data: ColumnarData;
}let input: {workbook:Workbook;data:ColumnarData;}let input: {workbook:Workbook;data:ColumnarData;}input: {
workbook: Workbook;
data: ColumnarData;
}let input: {workbook:Workbook;data:ColumnarData;}let input: {workbook:Workbook;data:ColumnarData;}workbook: Workbooklet workbook:Workbooklet workbook:WorkbookLive workbook schema adopted by the store and updated by document operations.API reference →interface WorkbookinterfaceWorkbookinterfaceWorkbookLive workbook schema containing ordered sheets and the active sheet ID.API reference →data: ColumnarDatalet data:ColumnarDatalet data:ColumnarDataEager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →interface ColumnarDatainterfaceColumnarDatainterfaceColumnarDataEager column-oriented values used to initialize a sheet.API reference →function $props(): { input: { workbook: Workbook; data: ColumnarData } }function$props(): {input: { workbook:Workbook; data:ColumnarData };}function$props(): {input: {workbook:Workbook;data:ColumnarData;};}Declares the props that a component accepts. Example: let { optionalProp = 42, requiredProp, bindableProp = $bindable() }: { optionalProp?: number; requiredProps: string; bindableProp: boolean } = $props();See also {@link svelte.dev/docs/svelte/$props Documentation}let activeGrid: Grid | undefinedlet activeGrid:Grid|undefinedlet activeGrid:Grid|undefinedAPI reference →function $state<Grid | undefined>(): Grid | undefined (+1 overload)
namespace $statefunction$state<Grid|undefined>():Grid|undefined (+1overload)namespace$statefunction$state<Grid|undefined>():Grid|undefined (+1overload)namespace$stateDeclares reactive state. Example: let count = $state(0);See also {@link svelte.dev/docs/svelte/$state Documentation}@param initial The initial valueAPI reference →interface GridinterfaceGridinterfaceGridImperative grid handle for document commands, events, rendering, and teardown.Exampleimporttype { Grid } from"@sheetwrite/core";functionupdateTotal(grid:Grid) {constsheet= grid.getActiveSheet();constresult= grid.applyTransaction({patches: [{ op: "set", addr: { sheet, row: 0, col: 0 }, value: { kind: "literal", value: 42 } }],});if (result.status ==="applied") grid.scrollToCell({ sheet, row: 0, col: 0 });return grid.aggregate(0, "sum");}See alsocreateGrid *See alsoGrid.applyTransactionAPI reference →(local function) ready(event: GridReadyEvent): void(local function) ready(event:GridReadyEvent):void(local function) ready(event:GridReadyEvent):voidResolves after durable work is restored and every startup commit is visible locally.API reference →interface GridReadyEventinterfaceGridReadyEventinterfaceGridReadyEventGrid handle, generation, and reason published after adapter initialization.API reference →GridReadyEvent.grid: GridinterfaceGridReadyEvent {grid:Grid;}interfaceGridReadyEvent {grid:Grid;}Live handle just published by the adapter; replaced on the next reset generation.API reference →const SheetwriteGrid: Component<SheetwriteGridProps<RowBridgeId>, {}, "grid">constSheetwriteGrid:Component<SheetwriteGridProps<RowBridgeId>,{},"grid">constSheetwriteGrid:Component<SheetwriteGridProps<RowBridgeId>,{},"grid">Advanced framework component for workbook data or datasource input.API reference →grid: Grid | undefinedlet grid:Grid|undefinedlet grid:Grid|undefinedLive handle just published by the adapter; replaced on the next reset generation.API reference →function onMount<T>(fn: () => NotFunction<T> | Promise<NotFunction<T>> | (() => any)): voidfunctiononMount<T>(fn: () =>NotFunction<T> |Promise<NotFunction<T>> | (() =>any),):voidfunctiononMount<T>(fn: () =>|NotFunction<T>|Promise<NotFunction<T>>| (() =>any),):voidonMount, like $effect, schedules a function to run as soon as the component has been mounted to the DOM. Unlike $effect, the provided function only runs once. It must be called during the component's initialisation (but doesn't need to live _inside_ the component; it can be called from an external module). If a function is returned _synchronously_ from onMount, it will be called when the component is unmounted. onMount functions do not run during server-side rendering.function fromXlsxTable(data: ArrayBuffer | Uint8Array, options?: XlsxWorkbookOptions): Promise<ColumnarData>functionfromXlsxTable(data:ArrayBuffer|Uint8Array,options?:XlsxWorkbookOptions,):Promise<ColumnarData>functionfromXlsxTable(data:ArrayBuffer|Uint8Array,options?:XlsxWorkbookOptions,):Promise<ColumnarData>Parse the first sheet of .xlsx bytes into ColumnarData. The first parsed row is treated as the header and its cell text becomes each column's key. Numbers stay numbers, date cells use the date-serial convention, strings are verbatim, and empty cells become null.Exampleimport { registerXlsxBackends } from"@sheetwrite/xlsx";import { fromXlsxTable } from"@sheetwrite/core";registerXlsxBackends();asyncfunctionopenTable(file:File) {returnfromXlsxTable(await file.arrayBuffer());}See alsotoXlsxTableAPI reference →function toXlsxWorkbook(input: WorkbookSnapshot | Pick<Grid, "exportSnapshot">, options?: XlsxWorkbookOptions): Promise<Uint8Array>functiontoXlsxWorkbook(input:WorkbookSnapshot|Pick<Grid, "exportSnapshot">,options?:XlsxWorkbookOptions,):Promise<Uint8Array>functiontoXlsxWorkbook(input:|WorkbookSnapshot|Pick<Grid,"exportSnapshot">,options?:XlsxWorkbookOptions,):Promise<Uint8Array>Formula-preserving, multi-sheet workbook export through the optional XLSX backend.Exampleimport { registerXlsxBackends } from"@sheetwrite/xlsx";import { toXlsxWorkbook, downloadBytes, type Grid } from"@sheetwrite/core";registerXlsxBackends();asyncfunctiondownload(grid:Grid) {constbytes=awaittoXlsxWorkbook(grid);downloadBytes(bytes, "workbook.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");}See alsofromXlsxWorkbookAPI reference →function downloadBytes(bytes: Uint8Array | string, filename: string, mime: string): voidfunctiondownloadBytes(bytes:Uint8Array|string,filename:string,mime:string,):voidfunctiondownloadBytes(bytes:Uint8Array|string,filename:string,mime:string,):voidTrigger a browser download from in-memory bytes. The temporary anchor is removed and its object URL is scheduled for revocation even when DOM append or click throws.API reference →function isSheetwriteError(value: unknown): value is SheetwriteErrorEnvelopefunctionisSheetwriteError(value:unknown,):valueisSheetwriteErrorEnvelopefunctionisSheetwriteError(value:unknown,):valueisSheetwriteErrorEnvelopeNarrow same-realm errors, cross-realm errors, and serialized failure envelopes.API reference →interface XlsxWorkbookOptionsinterfaceXlsxWorkbookOptionsinterfaceXlsxWorkbookOptionsShared options passed to every registered table and workbook XLSX backend.API reference →ColumnarData.rowCount: numberinterfaceColumnarData {rowCount:number;}interfaceColumnarData {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →ColumnarData.columns: Record<string, ArrayLike<CellScalar | CellValue>>interfaceColumnarData {columns:Record<string, ArrayLike<CellScalar|CellValue>>;}interfaceColumnarData {columns:Record<string,ArrayLike<CellScalar|CellValue>>;}Ordered schema; array positions are the zero-based column coordinates.API reference →type Item: string[]typeItem: string[]typeItem: string[]type Amount: number[]typeAmount: number[]typeAmount: number[](local function) workbookFor(data: ColumnarData): Workbook(local function) workbookFor(data:ColumnarData):Workbook(local function) workbookFor(data:ColumnarData):WorkbookWorkbook.activeSheet: stringinterfaceWorkbook {activeSheet:string;}interfaceWorkbook {activeSheet:string;}Active sheet ID and initial tab presented when the grid is created.API reference →Workbook.sheets: Sheet[]interfaceWorkbook {sheets:Sheet[];}interfaceWorkbook {sheets:Sheet[];}Sheets in display/tab order.API reference →Sheet.id: stringinterfaceSheet {id:string;}interfaceSheet {id:string;}Stable identifier, unique within the workbook and used by every cell address.API reference →Sheet.name: stringinterfaceSheet {name:string;}interfaceSheet {name:string;}User-facing sheet name shown in tabs and workbook exports.API reference →Sheet.rowCount: numberinterfaceSheet {rowCount:number;}interfaceSheet {rowCount:number;}Row count for both in-memory and datasource-backed sheets.API reference →Sheet.columns: Column[]interfaceSheet {columns:Column[];}interfaceSheet {columns:Column[];}Ordered schema; array positions are the zero-based column coordinates.API reference →var Object: ObjectConstructorvar Object:ObjectConstructorvar Object:ObjectConstructorProvides functionality common to all JavaScript objects.ObjectConstructor.keys(o: {}): string[] (+1 overload)ObjectConstructor.keys(o: {}): string[] (+1 overload)ObjectConstructor.keys(o: {}): string[] (+1 overload)Returns the names of the enumerable string properties and methods of an object.@param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.API reference →Array<string>.map<{
key: string;
header: string;
width: number;
type: "number" | "text";
}>(callbackfn: (value: string, index: number, array: string[]) => {
key: string;
header: string;
width: number;
type: "number" | "text";
}, thisArg?: any): {
key: string;
header: string;
width: number;
type: "number" | "text";
}[]Array<string>.map<{key:string;header:string;width:number;type:"number"|"text";}>(callbackfn: (value:string, index:number, array:string[]) => {key:string;header:string;width:number;type:"number"|"text";}, thisArg?:any): {key:string;header:string;width:number;type:"number"|"text";}[]Array<string>.map<{key:string;header:string;width:number;type:"number"|"text";}>(callbackfn: (value:string, index:number, array:string[]) => {key:string;header:string;width:number;type:"number"|"text";}, thisArg?:any): {key:string;header:string;width:number;type:"number"|"text";}[]Calls a defined callback function on each element of an array, and returns an array that contains the results.@param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.@param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.key: stringlet key:stringlet key:stringNon-empty key, unique within the sheet, used to map input and datasource values.API reference →header: stringlet header:stringlet header:stringSchema label used by table exports and data-grid presentation headers.API reference →width: numberlet width:numberlet width:numberUnzoomed column width in CSS pixels.API reference →type: "number" | "text"let type:"number"|"text"let type:"number"|"text"Controls cell input parsing and default value formatting for this column.API reference →const message: (error: unknown) => stringconstmessage: (error:unknown) =>stringconstmessage: (error:unknown,) =>stringerror: SheetwriteErrorEnvelopelet error:SheetwriteErrorEnvelopelet error:SheetwriteErrorEnvelopeAPI reference →SheetwriteErrorEnvelope.code: "conflict" | "incomplete-data" | "initialization-failed" | "initialization-required" | "datasource-request-failed" | "renderer-fallback" | "export-failed" | "xlsx-import-failed" | "optional-backend-unavailable" | "delimited-text-resource-limit" | "delimited-text-invalid-limit" | "xlsx-resource-limit" | "resource-limit" | "invalid-snapshot" | "aborted" | "not-found" | "commit-rejected" | "unavailable" | "blocked" | "quota" | "unsupported-schema" | "transaction" | "limit" | "invalid-limits" | "invalid-version" | "invalid-id" | ... 24 more ... | "shortcut-conflict"interfaceSheetwriteErrorEnvelope { code:"conflict"|"incomplete-data"|"initialization-failed"|"initialization-required"|"datasource-request-failed"|"renderer-fallback"|"export-failed"|"xlsx-import-failed"|"optional-backend-unavailable"|"delimited-text-resource-limit"|"delimited-text-invalid-limit"|"xlsx-resource-limit"|"resource-limit"|"invalid-snapshot"|"aborted"|"not-found"|"commit-rejected"|"unavailable"|"blocked"|"quota"|"unsupported-schema"|"transaction"|"limit"|"invalid-limits"|"invalid-version"|"invalid-id"| ... 24more ... |"shortcut-conflict" }interfaceSheetwriteErrorEnvelope { code:"conflict"|"incomplete-data"|"initialization-failed"|"initialization-required"|"datasource-request-failed"|"renderer-fallback"|"export-failed"|"xlsx-import-failed"|"optional-backend-unavailable"|"delimited-text-resource-limit"|"delimited-text-invalid-limit"|"xlsx-resource-limit"|"resource-limit"|"invalid-snapshot"|"aborted"|"not-found"|"commit-rejected"|"unavailable"|"blocked"|"quota"|"unsupported-schema"|"transaction"|"limit"|"invalid-limits"|"invalid-version"|"invalid-id"| ... 24more ... |"shortcut-conflict" }API reference →SheetwriteErrorEnvelope.message: stringinterfaceSheetwriteErrorEnvelope {message:string;}interfaceSheetwriteErrorEnvelope {message:string;}API reference →var String: StringConstructor
(value?: any) => stringvar String:StringConstructor;(value?:any) => stringvar String:StringConstructor;(value?:any) => stringAllows manipulation and formatting of text strings and determination and location of substrings within strings.error: unknownlet error:unknownlet error:unknownconst mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"constmime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"constmime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"function $state<{
workbook: Workbook;
data: ColumnarData;
}>(initial: {
workbook: Workbook;
data: ColumnarData;
}): {
workbook: Workbook;
data: ColumnarData;
} (+1 overload)
namespace $statefunction$state<{workbook:Workbook;data:ColumnarData;}>(initial: {workbook:Workbook;data:ColumnarData;}): {workbook:Workbook;data:ColumnarData;} (+1overload)namespace$statefunction$state<{workbook:Workbook;data:ColumnarData;}>(initial: {workbook:Workbook;data:ColumnarData;}): {workbook:Workbook;data:ColumnarData;} (+1overload)namespace$stateDeclares reactive state. Example: let count = $state(0);See also {@link svelte.dev/docs/svelte/$state Documentation}@param initial The initial valueconst initialData: ColumnarDataconstinitialData:ColumnarDataconstinitialData:ColumnarDataAPI reference →let busy: booleanlet busy:booleanlet busy:booleanfunction $state<false>(initial: false): false (+1 overload)
namespace $statefunction$state<false>(initial:false):false (+1overload)namespace$statefunction$state<false>(initial:false):false (+1overload)namespace$stateDeclares reactive state. Example: let count = $state(0);See also {@link svelte.dev/docs/svelte/$state Documentation}@param initial The initial valuelet error: stringlet error:stringlet error:stringfunction $state<"">(initial: ""): "" (+1 overload)
namespace $statefunction$state<"">(initial:""):"" (+1overload)namespace$statefunction$state<"">(initial:""):"" (+1overload)namespace$stateDeclares reactive state. Example: let count = $state(0);See also {@link svelte.dev/docs/svelte/$state Documentation}@param initial The initial valueconst controller: AbortControllerconstcontroller:AbortControllerconstcontroller:AbortControllervar AbortController: new () => AbortControllervar AbortController:new () =>AbortControllervar AbortController:new () =>AbortControllerThe AbortController interface represents a controller object that allows you to abort one or more Web requests as and when desired. MDN Reference An AbortController cancels one or more Web requests: pass its signal to a request, then call abort(). MDN ReferenceonMount<() => void>(fn: () => (() => any) | Promise<never>): voidonMount<() =>void>(fn: () => (() => any) |Promise<never>): voidonMount<() =>void>(fn: () => (() => any) |Promise<never>): voidonMount, like $effect, schedules a function to run as soon as the component has been mounted to the DOM. Unlike $effect, the provided function only runs once. It must be called during the component's initialisation (but doesn't need to live _inside_ the component; it can be called from an external module). If a function is returned _synchronously_ from onMount, it will be called when the component is unmounted. onMount functions do not run during server-side rendering.AbortController.abort(reason?: any): void (+1 overload)AbortController.abort(reason?: any): void (+1 overload)AbortController.abort(reason?: any): void (+1 overload)The abort() method of the AbortController interface aborts an asynchronous operation before it has completed. MDN Referencevar undefinedvar undefinedvar undefinedconst options: () => XlsxWorkbookOptionsconstoptions: () =>XlsxWorkbookOptionsconstoptions: () =>XlsxWorkbookOptionsAPI reference →XlsxWorkbookOptions.signal?: AbortSignal | undefinedinterfaceXlsxWorkbookOptions {signal?:AbortSignal|undefined;}interfaceXlsxWorkbookOptions {signal?:AbortSignal|undefined;}Abort before or between bounded codec operations.API reference →AbortController.signal: AbortSignalinterfaceAbortController {signal:AbortSignal;}interfaceAbortController {signal:AbortSignal;}The signal read-only property of the AbortController interface returns an AbortSignal object instance, which can be used to communicate with/abort an asynchronous operation as desired. MDN ReferenceAPI reference →XlsxWorkbookOptions.maxCells?: number | undefinedinterfaceXlsxWorkbookOptions {maxCells?:number|undefined;}interfaceXlsxWorkbookOptions {maxCells?:number|undefined;}Cells accounted by the active conversion path; defaults to 1,000,000.API reference →XlsxWorkbookOptions.resourceLimits?: Partial<Omit<XlsxResourceLimits, "maxCells">> | undefinedinterfaceXlsxWorkbookOptions {resourceLimits?:Partial<Omit<XlsxResourceLimits, "maxCells">> |undefined;}interfaceXlsxWorkbookOptions {resourceLimits?:|Partial<Omit<XlsxResourceLimits,"maxCells">>|undefined;}Positive overrides for every XLSX resource dimension except maxCells.API reference →maxInputBytes?: number | undefinedmaxInputBytes?: number |undefinedmaxInputBytes?: number |undefinedCompressed workbook input bytes; defaults to 32 MiB.API reference →XlsxWorkbookOptions.onWarning?: ((warning: XlsxWorkbookWarning) => void) | undefinedinterfaceXlsxWorkbookOptions {onWarning?: ((warning:XlsxWorkbookWarning) =>void) |undefined;}interfaceXlsxWorkbookOptions {onWarning?:| ((warning:XlsxWorkbookWarning,) =>void)|undefined;}warning: XlsxWorkbookWarninglet warning:XlsxWorkbookWarninglet warning:XlsxWorkbookWarningAPI reference →XlsxWorkbookWarning.message: stringinterfaceXlsxWorkbookWarning {message:string;}interfaceXlsxWorkbookWarning {message:string;}API reference →(local function) open(file: File): Promise<void>(local function) open(file:File):Promise<void>(local function) open(file:File):Promise<void>interface FileinterfaceFileinterfaceFileThe File interface provides information about files and allows JavaScript in a web page to access their content. MDN Referencefile: Filelet file:Filelet file:FileBlob.size: numberinterfaceBlob {size:number;}interfaceBlob {size:number;}The size read-only property of the Blob interface returns the size of the Blob or File in bytes. MDN Reference The size of this Blob in bytesvar Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)var Error:ErrorConstructornew (message?:string, options?:ErrorOptions) =>Error (+2 overloads)const data: ColumnarDataconstdata:ColumnarDataconstdata:ColumnarDataEager column-major values loaded into workbook.activeSheet; use instead of datasource.API reference →Blob.arrayBuffer(): Promise<ArrayBuffer> (+1 overload)Blob.arrayBuffer(): Promise<ArrayBuffer> (+1 overload)Blob.arrayBuffer(): Promise<ArrayBuffer> (+1 overload)Returns a promise that resolves to the contents of the blob as an ArrayBufferAbortSignal.aborted: booleaninterfaceAbortSignal {aborted:boolean;}interfaceAbortSignal {aborted:boolean;}The aborted read-only property returns a value that indicates whether the asynchronous operations the signal is communicating with are aborted (true) or not (false). MDN Reference(local var) failure: unknown(local var) failure: unknown(local var) failure: unknown(local function) save(): Promise<void>(local function) save():Promise<void>(local function) save():Promise<void>const current: Grid | undefinedconstcurrent:Grid|undefinedconstcurrent:Grid|undefinedAPI reference →const bytes: Uint8Array<ArrayBufferLike>constbytes:Uint8Array<ArrayBufferLike>constbytes:Uint8Array<ArrayBufferLike>const current: Gridconstcurrent:Gridconstcurrent:GridAPI reference →(local function) choose(event: Event): void(local function) choose(event:Event):void(local function) choose(event:Event):voidinterface EventinterfaceEventinterfaceEventThe Event interface represents an event which takes place on an EventTarget. MDN Referenceconst target: HTMLInputElementconsttarget:HTMLInputElementconsttarget:HTMLInputElementRelationship target part.API reference →event: Eventlet event:Eventlet event:EventEvent.currentTarget: EventTarget | nullinterfaceEvent {currentTarget:EventTarget|null;}interfaceEvent {currentTarget:EventTarget|null;}The currentTarget read-only property of the Event interface identifies the element to which the event handler has been attached. MDN Referenceinterface HTMLInputElementinterfaceHTMLInputElementinterfaceHTMLInputElementThe HTMLInputElement interface provides special properties and methods for manipulating the options, layout, and presentation of input elements. MDN Referenceconst file: File | undefinedconstfile:File|undefinedconstfile:File|undefinedHTMLInputElement.files: FileList | nullinterfaceHTMLInputElement {files:FileList|null;}interfaceHTMLInputElement {files:FileList|null;}The HTMLInputElement.files property allows you to access the FileList selected with the <input type='file'> element. MDN Referenceconst file: Fileconstfile:Fileconstfile:FileHTMLInputElement.value: stringinterfaceHTMLInputElement {value:string;}interfaceHTMLInputElement {value:string;}The value property of the HTMLInputElement interface represents the current value of the input element as a string. MDN Reference