xlsx-formula-recalc
v0.42.0
Published
Recalculate XLSX formulas in Node.js without Excel, LibreOffice, or browser automation.
Downloads
11,196
Maintainers
Readme
xlsx-formula-recalc
Recalculate XLSX formulas in Node.js without opening Excel, LibreOffice, or a browser.
This package is a narrow wrapper around Bilig WorkPaper for the high-friction Node XLSX workflow:
- import an XLSX workbook,
- edit input cells,
- recalculate formulas,
- read proof values,
- export an updated XLSX.
It fits the common xlsx-populate, SheetJS, and template-generation case
where the file writer can create or edit the XLSX, but the Node service also
needs fresh formula readback before returning.
If You Arrived From SheetJS or xlsx-populate
xlsx, SheetJS-style workbook objects, and xlsx-populate are good at file
I/O. They can read workbook bytes, write cells, preserve formulas, and export
an .xlsx artifact.
They do not make stale cached formula values fresh inside your Node process. That is the failure behind issues and searches like:
xlsx-populate formula calculated valueSheetJS formula result not updatingxlsx formula recalculation Node.jsget computed value from xlsx formula cell
Use this package at the file boundary:
- let your existing library produce XLSX bytes;
- call
recalculateXlsx(...); - read the proof cells from
result.reads; - write
result.xlsxif the recalculated workbook artifact is needed.
That keeps your current file-writer choice intact and adds only the missing calculation/readback step.
For a cross-library proof, run
examples/recalc-bridge-workflows.
It edits the same workbook through SheetJS/xlsx, xlsx-populate, and
ExcelJS, then verifies that Bilig refreshes the stale formula result.
For the SheetJS-specific boundary, read
SheetJS formula result not updating in Node.js.
The SheetJS-named sheetjs-formula-recalc package is also published for teams
that search and install through the SheetJS / xlsx pipeline. It uses the same
underlying recalculation implementation as this package.
npx --package sheetjs-formula-recalc sheetjs-recalc --demo --jsonInstall
npm install xlsx-formula-recalcCLI
Run a self-contained proof first:
npx --package xlsx-formula-recalc xlsx-recalc --demo --jsonThat command creates a tiny workbook, changes Inputs!B2 and Inputs!B3,
recalculates Summary!B2, writes bilig-formula-recalc-demo.xlsx, and prints
verified: true with the recalculated value.
For an existing workbook:
npx --package xlsx-formula-recalc xlsx-recalc pricing.xlsx \
--set Inputs!B2=48 \
--set Inputs!B3=1500 \
--read Summary!B7 \
--out pricing.recalculated.xlsx \
--jsonThe CLI writes a recalculated workbook and prints readback values. Cell targets must be sheet-qualified A1 references such as Inputs!B2 or 'Pricing Model'!F12.
API
import { recalculateXlsx } from 'xlsx-formula-recalc'
const result = recalculateXlsx(await fs.promises.readFile('pricing.xlsx'), {
edits: [
{ target: 'Inputs!B2', value: 48 },
{ target: 'Inputs!B3', value: 1500 },
],
reads: ['Summary!B7'],
})
await fs.promises.writeFile('pricing.recalculated.xlsx', result.xlsx)
console.log(result.reads['Summary!B7'])If another library already produced the workbook bytes, pass those bytes directly:
const output = await workbook.outputAsync('nodebuffer') // for example, from xlsx-populate
const result = recalculateXlsx(output, {
reads: ['Summary!B7'],
})For the full workbook API, import WorkPaper, importXlsx, and exportXlsx from this package.
Common Boundaries
| Existing tool | Keep using it for | Add this package when |
| -------------------------------------- | ------------------------------------------------------ | --------------------------------------------------- |
| xlsx-populate | template editing and workbook generation | formula cells need fresh cached values in Node |
| SheetJS / xlsx | broad XLSX parsing, writing, and file interchange | edited inputs must update dependent formulas now |
| ExcelJS | styled reports, sheets, tables, and ExcelJS workbooks | use exceljs-formula-recalc for the ExcelJS object |
| Excel, LibreOffice, Microsoft Graph | exact spreadsheet application behavior | you cannot depend on an external app or API call |
| @bilig/headless or bilig-workpaper | service-owned formula workbook state with JSON storage | the workbook does not have to stay XLSX-first |
Scope
Use this when a Node service needs deterministic formula readback after it changes XLSX inputs. It is not a full Excel clone: unsupported Excel functions, external workbook links, macros, and volatile functions may need review. Import warnings are returned in result.warnings.
