Features / Formulas / Iterative Calculation
Iterative Calculation

Iterative calculation is performed to repeatedly calculate a function until a specific numeric condition is met. DsExcel allows you to enable and perform iterative calculations by using EnableIterativeCalculation property of IFormulaOptions interface. Additionally, you can also set or retrieve the following:

For example, if MaximumIterations is set to 10 and MaximumChange is set to 0.001, DsExcel will stop calculating either after 10 calculations, or when there is a difference of less than 0.001 between the results.

 

Refer to the following example code to perform iterative calculation in a worksheet by performing 10 iterations.

C#
Copy Code
//create a new workbook
Workbook workbook = new Workbook();

//enable iterative calculation
workbook.Options.Formulas.EnableIterativeCalculation = true;
workbook.Options.Formulas.MaximumIterations = 10;
var worksheet = workbook.Worksheets[0];
worksheet.Range["A1"].Formula = "=B1 + 1";
worksheet.Range["B1"].Formula = "=A1 + 1";

Console.WriteLine("A1:" + worksheet.Range["A1"].Value.ToString());
Console.WriteLine("B1:" + worksheet.Range["B1"].Value.ToString());

workbook.Save("IterativeCalculation.xlsx");