exceljs-formula-recalc 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Proompt Engineering
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # exceljs-formula-recalc
2
+
3
+ Recalculate formulas in an ExcelJS workbook without opening Excel, LibreOffice, or a browser.
4
+
5
+ ExcelJS can read and write formula cells, but it does not run an Excel-compatible calculation engine for you after backend code edits inputs. This package bridges that gap: serialize the ExcelJS workbook, run the Bilig WorkPaper recalculation path, optionally load the recalculated XLSX back into the same ExcelJS workbook, and read proof values.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install exceljs exceljs-formula-recalc
11
+ ```
12
+
13
+ ## Use With ExcelJS
14
+
15
+ ```ts
16
+ import ExcelJS from "exceljs";
17
+ import { recalculateExceljsWorkbook } from "exceljs-formula-recalc";
18
+
19
+ const workbook = new ExcelJS.Workbook();
20
+ await workbook.xlsx.readFile("quote.xlsx");
21
+
22
+ const result = await recalculateExceljsWorkbook(workbook, {
23
+ edits: [
24
+ { target: "Inputs!B2", value: 48 },
25
+ { target: "Inputs!B3", value: 1500 },
26
+ ],
27
+ reads: ["Summary!B7"],
28
+ });
29
+
30
+ console.log(result.reads["Summary!B7"]);
31
+ await workbook.xlsx.writeFile("quote.recalculated.xlsx");
32
+ ```
33
+
34
+ By default, `recalculateExceljsWorkbook` mutates the provided ExcelJS workbook by loading the recalculated XLSX bytes back into it. For targets listed in `reads`, it also patches the ExcelJS formula cell object with the recalculated `result`, so backend code can inspect proof values without reopening the file. Pass `mutateWorkbook: false` if you only need the returned `xlsx` bytes.
35
+
36
+ ## API
37
+
38
+ ```ts
39
+ import {
40
+ recalculateExceljsBuffer,
41
+ recalculateExceljsWorkbook,
42
+ } from "exceljs-formula-recalc";
43
+ ```
44
+
45
+ `recalculateExceljsWorkbook(workbook, options)` accepts any workbook-like object with `workbook.xlsx.writeBuffer()` and `workbook.xlsx.load(...)`, which matches ExcelJS workbooks.
46
+
47
+ `recalculateExceljsBuffer(input, options)` accepts XLSX bytes and returns the same result shape as `xlsx-formula-recalc`.
48
+
49
+ Cell targets must be sheet-qualified A1 references such as `Inputs!B2` or `'Pricing Model'!F12`.
50
+
51
+ ## Scope
52
+
53
+ Use this when a Node service already uses ExcelJS for workbook I/O but needs deterministic formula readback after changing 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`.
@@ -0,0 +1,24 @@
1
+ import { type XlsxFormulaRecalcOptions, type XlsxFormulaRecalcResult } from 'xlsx-formula-recalc';
2
+ export { WorkPaper, exportXlsx, importXlsx, parseQualifiedA1, parseQualifiedCellTarget, recalculateXlsx } from 'xlsx-formula-recalc';
3
+ export type { XlsxFormulaRecalcCellValue, XlsxFormulaRecalcEdit, XlsxFormulaRecalcOptions, XlsxFormulaRecalcResult, } from 'xlsx-formula-recalc';
4
+ export interface ExceljsWorkbookLike {
5
+ readonly xlsx: {
6
+ writeBuffer(): Promise<ArrayBuffer | Buffer | Uint8Array>;
7
+ load(input: ArrayBuffer | Buffer | Uint8Array): Promise<unknown>;
8
+ };
9
+ getWorksheet?(name: string): ExceljsWorksheetLike | undefined;
10
+ }
11
+ export interface ExceljsWorksheetLike {
12
+ getCell(address: string): ExceljsCellLike;
13
+ }
14
+ export interface ExceljsCellLike {
15
+ value: unknown;
16
+ }
17
+ export interface ExceljsFormulaRecalcOptions extends XlsxFormulaRecalcOptions {
18
+ readonly mutateWorkbook?: boolean;
19
+ }
20
+ export interface ExceljsFormulaRecalcResult extends XlsxFormulaRecalcResult {
21
+ readonly workbookMutated: boolean;
22
+ }
23
+ export declare function recalculateExceljsWorkbook(workbook: ExceljsWorkbookLike, options?: ExceljsFormulaRecalcOptions): Promise<ExceljsFormulaRecalcResult>;
24
+ export declare function recalculateExceljsBuffer(input: Uint8Array | ArrayBuffer | Buffer, options?: XlsxFormulaRecalcOptions): XlsxFormulaRecalcResult;
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ import { parseQualifiedA1, recalculateXlsx } from 'xlsx-formula-recalc';
2
+ export { WorkPaper, exportXlsx, importXlsx, parseQualifiedA1, parseQualifiedCellTarget, recalculateXlsx } from 'xlsx-formula-recalc';
3
+ export async function recalculateExceljsWorkbook(workbook, options = {}) {
4
+ const { mutateWorkbook = true, ...recalcOptions } = options;
5
+ const input = await workbook.xlsx.writeBuffer();
6
+ const result = recalculateXlsx(toUint8Array(input), recalcOptions);
7
+ if (mutateWorkbook) {
8
+ await workbook.xlsx.load(result.xlsx);
9
+ patchExceljsReadResults(workbook, result.reads);
10
+ }
11
+ return {
12
+ ...result,
13
+ workbookMutated: mutateWorkbook,
14
+ };
15
+ }
16
+ export function recalculateExceljsBuffer(input, options = {}) {
17
+ return recalculateXlsx(input, options);
18
+ }
19
+ function toUint8Array(input) {
20
+ if (input instanceof Uint8Array) {
21
+ return input;
22
+ }
23
+ return new Uint8Array(input);
24
+ }
25
+ function patchExceljsReadResults(workbook, reads) {
26
+ if (!workbook.getWorksheet) {
27
+ return;
28
+ }
29
+ for (const [target, value] of Object.entries(reads)) {
30
+ const parsed = parseQualifiedA1(target);
31
+ const worksheet = workbook.getWorksheet(parsed.sheetName);
32
+ if (!worksheet) {
33
+ continue;
34
+ }
35
+ const cell = worksheet.getCell(`${columnIndexToLetters(parsed.col)}${parsed.row + 1}`);
36
+ const readValue = unwrapReadValue(value);
37
+ if (readValue === undefined) {
38
+ continue;
39
+ }
40
+ if (isExceljsFormulaCellValue(cell.value)) {
41
+ cell.value = {
42
+ ...cell.value,
43
+ result: readValue,
44
+ };
45
+ }
46
+ else {
47
+ cell.value = readValue;
48
+ }
49
+ }
50
+ }
51
+ function unwrapReadValue(value) {
52
+ if (typeof value === 'object' && value !== null && 'value' in value) {
53
+ return value.value;
54
+ }
55
+ return undefined;
56
+ }
57
+ function isExceljsFormulaCellValue(value) {
58
+ return typeof value === 'object' && value !== null && 'formula' in value && typeof value.formula === 'string';
59
+ }
60
+ function columnIndexToLetters(columnIndex) {
61
+ let value = columnIndex + 1;
62
+ let letters = '';
63
+ while (value > 0) {
64
+ const remainder = (value - 1) % 26;
65
+ letters = String.fromCharCode(65 + remainder) + letters;
66
+ value = Math.floor((value - 1) / 26);
67
+ }
68
+ return letters;
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAA+D,MAAM,qBAAqB,CAAA;AAEpI,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAgCpI,MAAM,CA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AG,SAAS,CAAC,GAAG,OAAO,CAAA;QACvD,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;IACtC,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "exceljs-formula-recalc",
3
+ "version": "0.30.2",
4
+ "description": "Recalculate ExcelJS XLSX workbook formulas in Node.js without Excel, LibreOffice, or browser automation.",
5
+ "keywords": [
6
+ "excel",
7
+ "excel-formulas",
8
+ "exceljs",
9
+ "exceljs-formulas",
10
+ "exceljs-recalc",
11
+ "formula-engine",
12
+ "formula-recalculation",
13
+ "node",
14
+ "spreadsheet",
15
+ "workbook",
16
+ "xlsx",
17
+ "xlsx-formula",
18
+ "xlsx-recalc",
19
+ "xlsx-recalculation"
20
+ ],
21
+ "homepage": "https://proompteng.github.io/bilig/exceljs-formula-recalculation-node.html",
22
+ "bugs": {
23
+ "url": "https://github.com/proompteng/bilig/issues"
24
+ },
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/proompteng/bilig.git",
29
+ "directory": "packages/exceljs-formula-recalc"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "type": "module",
37
+ "sideEffects": false,
38
+ "main": "./dist/index.js",
39
+ "types": "./dist/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.js"
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "dependencies": {
50
+ "xlsx-formula-recalc": "0.30.2"
51
+ },
52
+ "devDependencies": {
53
+ "exceljs": "4.4.0"
54
+ },
55
+ "peerDependencies": {
56
+ "exceljs": ">=4.4.0"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "exceljs": {
60
+ "optional": true
61
+ }
62
+ },
63
+ "engines": {
64
+ "node": ">=22.0.0"
65
+ },
66
+ "scripts": {
67
+ "build": "pnpm --dir ../.. --filter xlsx-formula-recalc build && rm -rf dist tsconfig.tsbuildinfo && tsc -p tsconfig.json"
68
+ }
69
+ }