在 javascript 中,如何将相同的 excel 公式放入 range/column 个单元格中,但公式会根据单元格发生变化?

In javascript, how can I put the same excel formula in a range/column of cells but have the formula change based on the cell?

我正在使用 xlsx-populate,但愿意使用任何东西。我希望在 column/range 中的每个单元格中使用相同的公式,但公式的编号会根据行号更改。

即。单元格 D1 中的公式为 =SUM(A1*B1),但在单元格 D4 的第 4 行中,该单元格中的公式为 =SUM(A4*B4).

我觉得我的函数很离谱(我不知道在函数参数里放什么等等)

    theNewSheet.range("D1:D9").forEach(function(cell, i) {
                        var celly = cell.row;
                        var cellFormula = "=SUM(A" + cellyNum + "*" + "B" + cellyNum + ")";       
                        cell.formula(cellFormula);
///formula in excel should look like =SUM(A?*B?), where "?" is the row number the cell is in

                    });

一次搞定。

var cellFormula = "=SUM(A1*B1)";       
theNewSheet.range("D1:D9").formula(cellFormula);

行号应从第 1 行到第 9 行递增。