如何使用ExcelJs从公式单元格中获取计算值.它是返回公式,而不是我在excel上看到的值



我正在使用ExcelJs读取excel文件。然而,当我得到公式单元格时,它不是给我值,而是给公式。有人能帮忙吗。

var Excel = require('exceljs');
let workbook = new Excel.Workbook();
var FormulaParser = require('hot-formula-parser').Parser;
var parser = new FormulaParser();
workbook.xlsx.readFile('test.xlsx').then(function() {
var worksheet = workbook.getWorksheet(2);
var row = worksheet.getRow(1);
console.log(row.getCell(1).value); //5
console.log(row.getCell(2).value); //8
console.log(row.getCell(3).value); // =IFERROR(MIN(MAX($A1-$B1,0),$E1),"")
console.log(row.getCell(3).text); // blank
//I also tried with using FormulaParser library as below but getting null.
console.log(parser.parse(row.getCell(3).formula).result); // null
});

结果如下:

console.log(row.getCell(3).result);

最新更新