How to parse ‘excel formula' using node js to get the actual value from the excel sheet. #2470
Replies: 4 comments 4 replies
-
|
Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
|
@vishal2159 Any solution for this issue? |
Beta Was this translation helpful? Give feedback.
-
|
@vishal2159 Did you find the solution for this? |
Beta Was this translation helpful? Give feedback.
-
|
ExcelJS will not calculate that value for you. It can read/write the formula object and any cached worksheet.getCell('A15').value
// { formula: 'B9', result: 'Action for Step 1' }That The practical choices are:
Disclosure: I maintain For your specific snippet, I would not expect this to ever work with ExcelJS alone: worksheet.getCell('A20').value = { formula: 'B9' }
console.log(worksheet.getCell('A20').value)At that point you have assigned a formula object; you have not run a calculation engine. You either need to pass the workbook through a calculator/runtime, or open/save it in an Excel-compatible engine that fills the cached results. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
we have the formula defined in a excel sheet that formula is reference to multiple cell values from another sheet in same excel file. we have to evalute that formula to get the value/result using node js. we have tried multiple npm packages but receiving formula instead of its value as the result.
Below are the packages we tried
1.exceljs
2. xlsx
3. 'xlsx-calc' and formulajs/formulajs'
4. hyperformula
const Excel = require('exceljs');
const workbook = new Excel.Workbook();
//Reading excel sheet here with passing path of sheet
workbook.xlsx.readFile("./SimpleExampleToTestExcelFormulaSettingInNodeJS.xlsx").then(() => {
var worksheet = workbook.getWorksheet("Sheet1");// In excel sheet1 is reading here
var templateSheet = workbook.getWorksheet("Sheet2");// In excel sheet2 is reading here
var XLSX_CALC = require('xlsx-calc');
var formulajs = require('@formulajs/formulajs');
//scenario 1
XLSX_CALC.import_functions(formulajs);
worksheet.C30 = { f: '=Template!H11'};
console.log("value", worksheet.C30.value);
//that time getting also same formula here
//scenario 2
XLSX_CALC.import_functions(formulajs);
worksheet.C30 = { f: '=Template!H11', v: "ghjhg" };
console.log("value", worksheet.C30.value);
//that time getting formula and value but value also set here
5.using xlsx npm
const reader = require('xlsx');
const workbook1 = reader.readFile(req.file.path);
var wb = workbook1.Sheets["FieldMapping"];
//scenario 1
var data = reader.utils.getCell(wb, 'A'+100 ,"=Template!E11",1)
//this one also not working proper
//scenario 2
reader.utils.sheet_set_array_formula(wb, "C1", "=Template!E11", 1);
//this time also get undefined value.
4 using 'hyperformula' Npm
const HyperFormula = require('hyperformula');
const data = ['=Template!E11'];
var setFormula = HyperFormula.buildFromArray(data ,’A’+100);
var getResult = hfInstance.getCellValue('A'+100);
console.log(getResult);
//This is also not working as expected.
Beta Was this translation helpful? Give feedback.
All reactions