Document Solutions for Excel, Java Edition | Document Solutions
Features / Formulas / Iterative Calculation
In This Topic
Iterative Calculation
In This Topic

Iterative calculations are supported by DsExcel. Along with that, you can specify the maximum number of iterations and maximum difference between the values of iterative formulas.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 setEnableIterativeCalculation method of IFormulaOptions interface. Additionally, you can also set or retrieve the following:

For example, if setMaximumIterations is set to 10 and setMaximumChange 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.

Java
Copy Code
```// Create a new workbook
Workbook workbook = new Workbook();

// Enable iterative calculation
workbook.getOptions().getFormulas().setEnableIterativeCalculation(true);
workbook.getOptions().getFormulas().setMaximumIterations(10);
IWorksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getRange("A1").setFormula("=B1 + 1");
worksheet.getRange("B1").setFormula("=A1 + 1");

System.out.println("A1:" + worksheet.getRange("A1").getValue().toString());
System.out.println("B1:" + worksheet.getRange("B1").getValue().toString());

// Save to an excel file
workbook.save("IterativeCalculation.xlsx");```