import "@sheetwrite/xlsx/register" ;
declare const bytes : ArrayBuffer | Uint8Array ;
For a workbook containing 10, 20 and =SUM(A1:A2) in A1:A3, the imported grid evaluates:
Imported worksheet: formula source retained in A3
The snapshot retains =SUM(A1:A2), not a cached result or a raw formula handle.
Try it live: import a source workbook .
Full setup
Install @sheetwrite/xlsx and register it on the import path. This complete example makes its own XLSX input:
} from "@sheetwrite/core" ;
import "@sheetwrite/xlsx/register" ;
Choose an import contract
Function Input Result fromXlsxWorkbook(data, options?)ArrayBuffer or Uint8ArrayPromise<WorkbookSnapshot>; preserves supported workbook state with no header synthesis.fromXlsxWorkbookFile(file, options?)File or BlobSame snapshot contract, without first buffering the compressed file. fromXlsxTable(data, options?)ArrayBuffer or Uint8ArrayPromise<ColumnarData>; one rectangular table with first-row headers and resolved scalars.
Table import reads boolean literals. It is not a workbook round-trip API. See the fidelity table for supported workbook state.
Workbook formulas import as source. SheetwriteStore.fromSnapshot recompiles them into the selected formula engine; no raw handles enter the serialized snapshot. Import also keeps eligible opaque parts .
Warnings
onWarning receives XlsxWorkbookWarning with code, message, and optional sheet, cell and part. Rich-text flattening uses rich-text; unsupported conditional rules use format-loss; dropped unmodelled features use structured warnings such as unsupported-feature. Do not assume that a successful import was lossless.
Supported native hyperlinks, conditional formats, tables, validation and notes are not all dropped merely because a file lacks Sheetwrite metadata. Unsupported content still produces warnings. The checked compatibility results distinguish evaluated, preserved, flattened, warning and unsupported behavior by file and producer.
Hyperlinks
Hyperlinks retain stable IDs in Sheetwrite metadata. Internal targets use stable sheet IDs: a sheet rename does not retarget a link. Removing the destination atomically removes inbound links; undo restores them with the sheet. Activation of stale host-held targets fails closed.
External mutation and activation allow only absolute https:// and mailto: targets. javascript:, data:, file:, HTTP, credentials, malformed URLs and internal OOXML relationship traversal are rejected before document mutation or activation.
Sheetwrite never calls window.open. Ctrl/Meta-click and grid.activateHyperlink() emit hyperlink-activate with a validated target. Set hyperlinkActivation: "internal-navigation" to also navigate internal targets, or "disabled" to suppress activation.
Rules run in array order. Earlier rules have style precedence. A matching stopIfTrue blocks later rules from the main/Worker match mask. Formula predicates are anchored at the rule range's top-left: relative A1 references move per cell; $-absolute components stay fixed.
A sheet supports at most 32 rules (the renderer's deterministic u32 mask). One predicate formula is limited to 8,192 characters. SpreadsheetML cellIs, blank/text and expression rules round-trip with priority and stop behavior. Color scales, data bars, icon sets and unrepresentable differential styles enter neither the live model nor the renderer. Import emits a deterministic format-loss warning naming the dropped rule kind.
Options and limits
Every import path uses XlsxWorkbookOptions. Missing registration and codec errors reject with SheetwriteError; resource errors remain XlsxResourceError and satisfy isSheetwriteError. Read error code rather than matching installation text. Use bounded resource options , including cancellation, for untrusted files.
See also
function fromXlsxWorkbook(data: ArrayBuffer | Uint8Array, options?: XlsxWorkbookOptions): Promise<WorkbookSnapshot> function fromXlsxWorkbook (
data : ArrayBuffer | Uint8Array ,
options ?: XlsxWorkbookOptions ,
) : Promise < WorkbookSnapshot > function fromXlsxWorkbook (
data : ArrayBuffer | Uint8Array ,
options ?: XlsxWorkbookOptions ,
) : Promise < WorkbookSnapshot > Formula-preserving, multi-sheet workbook import through the optional XLSX backend. Example import { registerXlsxBackends } from "@sheetwrite/xlsx" ;
import { fromXlsxWorkbook, createGridFromSnapshot, initSheetwrite } from "@sheetwrite/core" ;
registerXlsxBackends ();
async function openWorkbook ( host : HTMLElement , file : File ) {
await initSheetwrite ();
const snapshot = await fromXlsxWorkbook ( await file. arrayBuffer ());
return createGridFromSnapshot (host, snapshot);
} See also toXlsxWorkbook API reference → class SheetwriteStore class SheetwriteStore class SheetwriteStore Stable public facade and the sole transaction, epoch, policy, and event barrier. Example import { initSheetwrite, SheetwriteStore, type Workbook } from "@sheetwrite/core" ;
async function total ( workbook : Workbook ) {
await initSheetwrite ();
const store = new SheetwriteStore (workbook);
try {
return store. aggregate (workbook.activeSheet, 0 , "sum" );
} finally {
store. dispose ();
}
} See also Store.aggregate * See also createGrid API reference → const bytes: ArrayBuffer | Uint8Array<ArrayBufferLike> const bytes : ArrayBuffer | Uint8Array < ArrayBufferLike > const bytes :
| ArrayBuffer
| Uint8Array < ArrayBufferLike > interface ArrayBuffer interface ArrayBuffer interface ArrayBuffer Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed. interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> interface Uint8Array < TArrayBuffer extends ArrayBufferLike = ArrayBufferLike > interface Uint8Array < TArrayBuffer extends ArrayBufferLike = ArrayBufferLike > A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised. const snapshot: WorkbookSnapshot const snapshot : WorkbookSnapshot const snapshot : WorkbookSnapshot API reference → XlsxWorkbookOptions.onWarning?: ((warning: XlsxWorkbookWarning) => void) | undefined interface XlsxWorkbookOptions {
onWarning ?: (( warning : XlsxWorkbookWarning ) => void ) | undefined ;
} interface XlsxWorkbookOptions {
onWarning ?:
| ((
warning : XlsxWorkbookWarning ,
) => void )
| undefined ;
} warning: XlsxWorkbookWarning let warning : XlsxWorkbookWarning let warning : XlsxWorkbookWarning API reference → var console: Console var console : Console var console : Console Console.warn(...data: any[]): void (+1 overload) Console. warn ( ... data: any[]): void ( + 1 overload) Console. warn ( ... data: any[]): void ( + 1 overload) The console.warn() static method outputs a warning message to the console at the 'warning' log level. MDN Reference XlsxWorkbookWarning.code: "boolean-literal" | "rich-text" | "hyperlink" | "unsupported-cell-value" | "unsupported-feature" | "external-relationship" | "external-formula" | "format-loss" | "validation-loss" | "invalid-metadata" interface XlsxWorkbookWarning {
code :
| "boolean-literal"
| "rich-text"
| "hyperlink"
| "unsupported-cell-value"
| "unsupported-feature"
| "external-relationship"
| "external-formula"
| "format-loss"
| "validation-loss"
| "invalid-metadata" ;
} interface XlsxWorkbookWarning {
code :
| "boolean-literal"
| "rich-text"
| "hyperlink"
| "unsupported-cell-value"
| "unsupported-feature"
| "external-relationship"
| "external-formula"
| "format-loss"
| "validation-loss"
| "invalid-metadata" ;
} API reference → XlsxWorkbookWarning.message: string interface XlsxWorkbookWarning {
message : string ;
} interface XlsxWorkbookWarning {
message : string ;
} API reference → const importedStore: SheetwriteStore const importedStore : SheetwriteStore const importedStore : SheetwriteStore API reference → SheetwriteStore.fromSnapshot(input: unknown, options?: SheetwriteStoreOptions): SheetwriteStore SheetwriteStore. fromSnapshot (input: unknown, options ?: SheetwriteStoreOptions): SheetwriteStore SheetwriteStore. fromSnapshot (input: unknown, options ?: SheetwriteStoreOptions): SheetwriteStore function initSheetwrite(source?: BufferSource | URL | string | Request | WebAssembly.Module, engine?: SheetwriteEngine): Promise<void> function initSheetwrite (
source ?:
BufferSource | URL | string | Request | WebAssembly . Module ,
engine ?: SheetwriteEngine ,
) : Promise < void > function initSheetwrite (
source ?:
| BufferSource
| URL
| string
| Request
| WebAssembly . Module ,
engine ?: SheetwriteEngine ,
) : Promise < void > Load one WASM engine before createGrid. The default is @sheetwrite/wasm. Pass the @sheetwrite/formulas module as the second argument to select the full engine. Example import { initSheetwrite } from "@sheetwrite/core" ;
import * as formulas from "@sheetwrite/formulas" ;
await initSheetwrite ( undefined , formulas); See also /docs/start/choose-an-engine/ See also createGrid API reference → function toXlsxWorkbook(input: WorkbookSnapshot | Pick<Grid, "exportSnapshot">, options?: XlsxWorkbookOptions): Promise<Uint8Array> function toXlsxWorkbook (
input : WorkbookSnapshot | Pick < Grid , "exportSnapshot" >,
options ?: XlsxWorkbookOptions ,
) : Promise < Uint8Array > function toXlsxWorkbook (
input :
| WorkbookSnapshot
| Pick <
Grid ,
"exportSnapshot"
>,
options ?: XlsxWorkbookOptions ,
) : Promise < Uint8Array > Formula-preserving, multi-sheet workbook export through the optional XLSX backend. Example import { registerXlsxBackends } from "@sheetwrite/xlsx" ;
import { toXlsxWorkbook, downloadBytes, type Grid } from "@sheetwrite/core" ;
registerXlsxBackends ();
async function download ( grid : Grid ) {
const bytes = await toXlsxWorkbook (grid);
downloadBytes (bytes, "workbook.xlsx" , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
} See also fromXlsxWorkbook API reference → interface WorkbookSnapshot interface WorkbookSnapshot interface WorkbookSnapshot Schema-versioned serializable workbook document. API reference → const source: WorkbookSnapshot const source : WorkbookSnapshot const source : WorkbookSnapshot Remote input is observable but never belongs in outgoing local persistence. API reference → WorkbookSnapshot.schemaVersion: 1 interface WorkbookSnapshot {
schemaVersion : 1 ;
} interface WorkbookSnapshot {
schemaVersion : 1 ;
} API reference → WorkbookSnapshot.workbook: {
activeSheet: SheetId;
namedRanges?: NamedRangeSnapshot[];
xlsxSource?: XlsxSourceSnapshot;
calculation?: CalculationSettings;
} interface WorkbookSnapshot {
workbook : {
activeSheet : SheetId ;
namedRanges ?: NamedRangeSnapshot [];
xlsxSource ?: XlsxSourceSnapshot ;
calculation ?: CalculationSettings ;
};
} interface WorkbookSnapshot {
workbook : {
activeSheet : SheetId ;
namedRanges ?: NamedRangeSnapshot [];
xlsxSource ?: XlsxSourceSnapshot ;
calculation ?: CalculationSettings ;
};
} Live workbook schema adopted by the store and updated by document operations. API reference → activeSheet: string let activeSheet : string let activeSheet : string Active sheet ID and initial tab presented when the grid is created. API reference → WorkbookSnapshot.sheets: SheetSnapshot[] interface WorkbookSnapshot {
sheets : SheetSnapshot [];
} interface WorkbookSnapshot {
sheets : SheetSnapshot [];
} Sheets in display/tab order. API reference → SheetSnapshot.id: string interface SheetSnapshot {
id : string ;
} interface SheetSnapshot {
id : string ;
} Stable identity used by operations, history, and collaboration rebase. API reference → SheetSnapshot.name: string interface SheetSnapshot {
name : string ;
} interface SheetSnapshot {
name : string ;
} User-facing caption. API reference → SheetSnapshot.order: number interface SheetSnapshot {
order : number ;
} interface SheetSnapshot {
order : number ;
} API reference → SheetSnapshot.rowCount: number interface SheetSnapshot {
rowCount : number ;
} interface SheetSnapshot {
rowCount : number ;
} Row count for both in-memory and datasource-backed sheets. API reference → SheetSnapshot.columns: Column[] interface SheetSnapshot {
columns : Column [];
} interface SheetSnapshot {
columns : Column [];
} Keys are stable, unique document column identities as well as datasource keys. API reference → Column.key: string interface Column {
key : string ;
} interface Column {
key : string ;
} Non-empty key, unique within the sheet, used to map input and datasource values. API reference → Column.header: string interface Column {
header : string ;
} interface Column {
header : string ;
} Schema label used by table exports and data-grid presentation headers. API reference → Column.width: number interface Column {
width : number ;
} interface Column {
width : number ;
} Unzoomed column width in CSS pixels. API reference → Column.type: CellFormat interface Column {
type : CellFormat ;
} interface Column {
type : CellFormat ;
} Controls cell input parsing and default value formatting for this column. API reference → SheetSnapshot.cells: CellBlock[] interface SheetSnapshot {
cells : CellBlock [];
} interface SheetSnapshot {
cells : CellBlock [];
} CellBlock.startRow: number interface CellBlock {
startRow : number ;
} interface CellBlock {
startRow : number ;
} API reference → CellBlock.startCol: number interface CellBlock {
startCol : number ;
} interface CellBlock {
startCol : number ;
} API reference → CellBlock.rowCount: number interface CellBlock {
rowCount : number ;
} interface CellBlock {
rowCount : number ;
} Row count for both in-memory and datasource-backed sheets. API reference → CellBlock.colCount: number interface CellBlock {
colCount : number ;
} interface CellBlock {
colCount : number ;
} API reference → CellBlock.cells: SnapshotCell[] interface CellBlock {
cells : SnapshotCell [];
} interface CellBlock {
cells : SnapshotCell [];
} SnapshotCell.rowOffset: number interface SnapshotCell {
rowOffset : number ;
} interface SnapshotCell {
rowOffset : number ;
} API reference → SnapshotCell.colOffset: number interface SnapshotCell {
colOffset : number ;
} interface SnapshotCell {
colOffset : number ;
} API reference → SnapshotCell.value: CellValue interface SnapshotCell {
value : CellValue ;
} interface SnapshotCell {
value : CellValue ;
} value: CellScalar let value : CellScalar let value : CellScalar API reference → src: string let src : string let src : string const bytes: Uint8Array<ArrayBufferLike> const bytes : Uint8Array < ArrayBufferLike > const bytes : Uint8Array < ArrayBufferLike > Console.log(...data: any[]): void (+1 overload) Console. log ( ... data: any[]): void ( + 1 overload) Console. log ( ... data: any[]): void ( + 1 overload) The console.log() static method outputs a message to the console. MDN Reference SheetwriteStore.exportSnapshot(): WorkbookSnapshot SheetwriteStore. exportSnapshot (): WorkbookSnapshot SheetwriteStore. exportSnapshot (): WorkbookSnapshot Deterministic, JSON-safe authoritative runtime document. API reference →