@8sheets/angular
v1.6.0
Published
Angular component for 8sheets, the Excel-compatible spreadsheet: <eight-sheet>, standalone, with typed outputs.
Maintainers
Readme
8sheets for Angular
<eight-sheet> (SheetComponent) puts an 8sheets workbook, an Excel-compatible spreadsheet, in an Angular app. It is a standalone component for Angular 17 and later, with zone.js or zoneless, and with server rendering. Its outputs are typed.
Install
npm i @8sheets/angular @8sheets/coreThen serve @8sheets/core as static files: add it to the assets of your build target in angular.json.
"assets": [
{ "glob": "**/*", "input": "node_modules/@8sheets/core", "output": "8sheets", "ignore": ["**/*.d.ts", "*.md", "package.json"] }
]The component loads 8sheets at run time from 8sheets/api/index.js, read against the page's <base href>, and only on a page that shows a sheet. 8sheets finds its Workers, icons, dictionaries and map data next to its own modules, and the Angular CLI bundles modules from node_modules without those files, so a bundled 8sheets could neither open nor save files. Served as it is, every file stays where its modules expect it, and your app's bundle doesn't grow.
To serve it from another path or a CDN, provide the URL of api/index.js:
import { EIGHT_SHEETS_URL } from '@8sheets/angular';
providers: [{ provide: EIGHT_SHEETS_URL, useValue: '/static/8sheets/api/index.js' }]Use
import { Component, signal } from '@angular/core';
import { SheetComponent, SheetEventPayload, SheetOptions, SheetsWorkbook } from '@8sheets/angular';
@Component({
selector: 'app-budget',
imports: [SheetComponent],
template: `
<eight-sheet class="grid" [options]="options()" (ready)="wb = $event"
(cellsChanged)="changed($event)" (beforeSheetRemove)="$event.cancel()" />
`,
styles: `.grid { height: 480px; }`,
})
export class Budget {
options = signal<SheetOptions>({ chrome: 'light', parts: { titleBar: false } });
wb?: SheetsWorkbook;
changed(e: SheetEventPayload) { console.log(e['count'], 'cells'); }
}<eight-sheet> is a block element with height: 100%, so it needs a parent with a height, or a class or style that sets one.
optionsgoes tomountWorkbook:parts,chrome,theme,fileName,language,data,sheetsand every option in the API reference. Pass a new object to change options: only the changed keys go towb.setOptions, with no remount.dataandsheetsact only at mount.- Outputs are the event names in camel case (
cellsChanged,selectionChanged,beforeSheetRemove), plusreadyandsheetError. They emit synchronously, so$event.cancel()in abefore…handler stops the action. An output nobody binds doesn't listen. - The component has
workbook,openFile(file)andsaveXlsx(sink?)(aBlobwithout a sink). - Change detection: the grid runs outside Angular's zone; only the outputs you bind re-enter it.
- Server rendering: it mounts in
afterNextRender, so the server renders an empty element and never loads 8sheets.
Cross-origin isolation
8sheets uses SharedArrayBuffer when the page is cross-origin isolated, and runs without it otherwise. To turn it on, send Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: credentialless; require-corp would block =IMAGE() pictures from other sites.
Documentation
React, Vue and Angular, For developers and the API reference for everything on the workbook.
Licence
8sheets is commercial software, not open source. You may install it and try it for free, to evaluate it. Using it in a product, or deploying it for your users or your own staff, needs a licence from 8sheets.com/pricing: Internal 999 USD or SaaS / OEM 2,999 USD, each paid once per company and covering every developer and every deployment, or Enterprise, quoted. There is no licence key and nothing in the package checks for one. The terms are in LICENSE.md and, once you hold a licence, the 8sheets Source Licence.
