Can the parser be use as a stand alone? #1073
codersbet
started this conversation in
API Questions
Replies: 1 comment
-
Hi @codersbet, thanks for reaching out to us! Method 1If you don't want to put your data into an array you can call calculateFormula() to use HyperFormula as an advanced calculator: const hf = HyperFormula.buildFromArray([]);
const data = [
{ name: 'test1', salary: 1500 },
{ name: 'test2', salary: 2000 },
];
const salaries = data.map(item => item.salary).join(',');
const totalSalary = hf.calculateFormula(`=SUM(${salaries})`, 0); Method 2You can put your data into an array and define a named expression const data = [
{ name: 'test1', salary: 1500 },
{ name: 'test2', salary: 2000 },
];
const dataArray = data.map(item => [ item.name, item.salary ]);
const hf = HyperFormula.buildFromSheets(
{ Data: dataArray },
{},
[{ name: 'Salary', expression: '=Data!$B:$B' }]
);
const totalSalary = hf.calculateFormula('=SUM(Salary)', 0); I hope one of these methods solves your problem ;) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to know if I can use the parser without a data table. i.e. say if I have a data=[{name: 'test', salary:1500}, {name: 'test', salary:2000} ] can do something like SUM(salary)
Beta Was this translation helpful? Give feedback.
All reactions