2

I am trying to generate an Excel sheet using Exceljs on NodeJS. I need to get a particular cell (E4) for which I have this code written.

var row = worksheet.getRow(4);
var compInfra = row.getCell(5);

The cell ('E4') contains a value as the result of a formula ('E4 = C4+D4'), which I have defined previously. C4 and D4 contain non zero numbers.

I need to use this resultant value of the formula in a subsequent statement as below:

row = worksheet.getRow(20);
row.getCell(5).value = compInfra * worksheet.getCell('A20');

I get no output on my Excel sheet at 'E20', since the value in 'E4' is a result of the formula. If I choose any other cell with some value instead of a formula, I get the result correctly. How do I address this issue.

Thanks in advance

Raja
  • 71
  • 1
  • 5
  • 1
    Your problem is that exceljs does not process formulas, and therefore cannot accomplish what you want. You'll have to implement a formula evaluator yourself. This means implementing Excel. – Robert Kawecki Mar 31 '21 at 13:23
  • I just need to set a cell value to a formula, with one of the inputs to it obtained from another cell (which in turn is an output resulting from a formula). If it is not possible, then I would have to look for other plugins or other options :( – Raja Apr 01 '21 at 05:55

1 Answers1

2
  worksheet.getCell('E4').value = { formula: 'C4+D4' };

  worksheet.getCell('C4').value = 7;
  worksheet.getCell('D4').value = 5;

https://github.com/exceljs/exceljs#formula-value