TRY NEW VERSION

NPV

NPV() → { number | string | boolean }

Returns the net present value of an investment based on a discount rate and a series of future payments (negative values) and income (positive values).

Parameters:

This method doesn't have any parameters.

Returns:

Type
number | string | boolean

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var oFunction = Api.GetWorksheetFunction();
oWorksheet.GetRange("A1").SetValue("Rate");
oWorksheet.GetRange("A2").SetValue(0.05);
var values = ["Payment", -10000, 3000, 4500, 6000];

for (var i = 0; i < values.length; i++) {
    oWorksheet.GetRange("B" + (i + 1)).SetValue(values[i]);
}
var oRange = oWorksheet.GetRange("B2:B5");
oWorksheet.GetRange("B6").SetValue(oFunction.NPV(0.05, oRange));
builder.SaveFile("xlsx", "NPV.xlsx");
builder.CloseFile();

Resulting document