Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dist/calx.esm.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/calx.esm.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/calx.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/calx.js.map

This file was deleted.

6 changes: 6 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Calx } from "./Calx";
import { Workbook } from "./Calx/Workbook";
import { Sheet } from "./Calx/Sheet";
import { Cell } from "./Calx/Cell";
export { Calx, Workbook, Sheet, Cell };
export default Calx;
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.calx.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.calx.js.map

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions examples/exportJSON.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Calx } from '../src/Calx';

// Example: Export and reload a workbook

// 1. Create a workbook with data
console.log('Creating workbook...');
const workbook1 = Calx.createWorkbook();
const sheet1 = workbook1.createSheet('Sales');

// Add some data
sheet1.createCell('A1', { value: 100 });
sheet1.createCell('A2', { value: 200 });
sheet1.createCell('A3', { value: 150 });
sheet1.createCell('A4', { formula: '=SUM(A1:A3)' });
sheet1.createCell('B1', { formula: '=A1*0.1' });

workbook1.build();
workbook1.calculate();

console.log('Original workbook values:');
console.log('A1:', sheet1.getCellValue('A1'));
console.log('A4 (SUM):', sheet1.getCellValue('A4'));
console.log('B1 (Tax):', sheet1.getCellValue('B1'));

// 2. Export to JSON
console.log('\nExporting to JSON...');
const data = workbook1.exportJSON();
const jsonString = JSON.stringify(data, null, 2);
console.log('Exported JSON:', jsonString);

// 3. Reload from JSON
console.log('\nReloading from JSON...');
const workbook2 = Calx.createWorkbookFromData(data);
const sheet2 = workbook2.getSheet('Sales') as any;

workbook2.build();
workbook2.calculate();

console.log('Reloaded workbook values:');
console.log('A1:', sheet2.getCellValue('A1'));
console.log('A4 (SUM):', sheet2.getCellValue('A4'));
console.log('B1 (Tax):', sheet2.getCellValue('B1'));

// 4. Verify formulas are preserved
console.log('\nFormulas preserved:');
console.log('A4 formula:', sheet2.getCell('A4').formula);
console.log('B1 formula:', sheet2.getCell('B1').formula);

console.log('\n✓ Export/Import successful!');
19 changes: 15 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ module.exports = {
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
'^@/(.*)$': '<rootDir>/src/$1',
'^@chevrotain/utils$': '<rootDir>/node_modules/@chevrotain/utils/lib/src/api.js',
'^@chevrotain/gast$': '<rootDir>/node_modules/@chevrotain/gast/lib/src/api.js',
'^@chevrotain/regexp-to-ast$': '<rootDir>/node_modules/@chevrotain/regexp-to-ast/lib/src/api.js',
'^@chevrotain/types$': '<rootDir>/node_modules/@chevrotain/types/lib/src/api.js',
'^@chevrotain/cst-dts-gen$': '<rootDir>/node_modules/@chevrotain/cst-dts-gen/lib/src/api.js'
},
modulePaths: ['<rootDir>/node_modules'],
transform: {
'^.+\\.ts$': ['ts-jest', {
tsconfig: 'tsconfig.test.json'
'^.+\\.(ts|tsx|js|jsx)$': ['ts-jest', {
tsconfig: 'tsconfig.test.json',
useESM: false
}]
}
},
transformIgnorePatterns: [
'node_modules/(?!(chevrotain|lodash-es|@chevrotain)/)'
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json']
};
Loading
Loading