Formula-backed state
Create sheets, write cells, evaluate formulas, and inspect calculated values through a typed API.
workbook runtime for code
bilig gives TypeScript programs a workbook API: formulas, sheet edits, structural operations, snapshots, and restore paths without driving a browser spreadsheet UI.
A grid component is the wrong primitive for backend jobs, coding agents, and local-first sync. bilig keeps the workbook model addressable from code.
Create sheets, write cells, evaluate formulas, and inspect calculated values through a typed API.
Move cells, apply workbook operations, undo and redo changes, and preserve state through snapshots.
Stable document and request shapes let tools mutate workbook state without screen scraping or hidden UI state.
The first evaluation path uses npm only. It builds a formula-backed workbook, edits source data, persists the document, restores it, and verifies the recalculated value.
mkdir bilig-headless-eval
cd bilig-headless-eval
npm init -y
npm pkg set type=module
npm install @bilig/headless
eval.mjs and run node eval.mjs
expected output includes total revenue before and after an edit, the restored sheet names, and a positive serialized byte count.
import {
WorkPaper,
createWorkPaperFromDocument,
exportWorkPaperDocument,
parseWorkPaperDocument,
serializeWorkPaperDocument,
} from "@bilig/headless";
const workbook = WorkPaper.buildFromSheets({
Revenue: [
["Region", "Customers", "ARPA", "Revenue"],
["West", 20, 1200, "=B2*C2"],
["East", 30, 250, "=B3*C3"],
["Central", 18, 300, "=B4*C4"],
],
Summary: [
["Metric", "Value"],
["Total revenue", "=SUM(Revenue!D2:D4)"],
],
});
const revenue = workbook.getSheetId("Revenue");
const summary = workbook.getSheetId("Summary");
if (revenue === undefined || summary === undefined) {
throw new Error("missing sheet");
}
const before = workbook.getCellValue({ sheet: summary, row: 1, col: 1 });
workbook.setCellContents({ sheet: revenue, row: 1, col: 1 }, 32);
const saved = serializeWorkPaperDocument(exportWorkPaperDocument(workbook, { includeConfig: true }));
const restored = createWorkPaperFromDocument(parseWorkPaperDocument(saved));
const restoredSummary = restored.getSheetId("Summary");
if (restoredSummary === undefined) {
throw new Error("missing restored sheet");
}
const after = restored.getCellValue({ sheet: restoredSummary, row: 1, col: 1 });
console.log({ before, after, sheets: restored.getSheetNames(), bytes: saved.length });
Use bilig where workbook semantics matter more than a rendered grid.
| Capability | Status |
|---|---|
| Programmatic workbook creation | available |
| Formula evaluation and readback | available |
| Structural edits and undo/redo | available |
| Snapshot and restore | available |
Start from artifacts, not claims. The repo includes examples, benchmark notes, and public issue threads for adoption work.