[]
        
(Showing Draft Content)

IFormulaOptions

Interface IFormulaOptions


public interface IFormulaOptions
Represents the options related to formula calculation, performance, and error handling.

Use this interface to configure workbook-level formula behavior, such as iterative calculation and its related limits. Obtain an instance from IExcelOptions.getFormulas().


 IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
 formulaOptions.setEnableIterativeCalculation(true);
 formulaOptions.setMaximumIterations(2);
 IWorksheet sheet = workbook.getActiveSheet();
 sheet.getRange("B1").setFormula("=A1+1");
 sheet.getRange("C1").setFormula("=B1+1");
 sheet.getRange("D1").setFormula("=C1+1");
 sheet.getRange("A1").setFormula("=D1+1");
 Object value = sheet.getRange("A1").getValue();
 
  • Method Details

    • getEnableIterativeCalculation

      boolean getEnableIterativeCalculation()
      Gets whether iterative calculation is enabled for formulas with circular references.

      When enabled, the workbook iteratively calculates formulas that contain circular references until the maximum number of iterations or maximum error threshold is reached.

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       formulaOptions.setEnableIterativeCalculation(true);
       formulaOptions.setMaximumIterations(10);
       boolean enabled = formulaOptions.getEnableIterativeCalculation();
       
      Returns:
      true if iterative calculation is enabled for formulas with circular references; otherwise, false.
    • setEnableIterativeCalculation

      void setEnableIterativeCalculation(boolean value)
      Sets whether iterative calculation is enabled for formulas with circular references.

      When enabled, the workbook iteratively calculates formulas that contain circular references until the maximum number of iterations or maximum error threshold is reached.

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       formulaOptions.setEnableIterativeCalculation(true);
       formulaOptions.setMaximumIterations(10);
       
      Parameters:
      value - true to enable iterative calculation for formulas with circular references; otherwise, false.
    • getMaximumIterations

      int getMaximumIterations()
      Gets the maximum iterations of iterative calculation.

      When iterative calculation is enabled, formulas are recalculated until the maximum number of iterations is reached or the maximum error threshold is met.

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       formulaOptions.setEnableIterativeCalculation(true);
       formulaOptions.setMaximumIterations(10);
       int maximumIterations = formulaOptions.getMaximumIterations();
       
      Returns:
      The maximum number of iterations allowed for iterative calculation.
    • setMaximumIterations

      void setMaximumIterations(int value)
      Sets the maximum iterations of iterative calculation.

      When iterative calculation is enabled, formulas are recalculated until the maximum number of iterations is reached or the maximum error threshold is met.

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       formulaOptions.setEnableIterativeCalculation(true);
       formulaOptions.setMaximumIterations(10);
       
      Parameters:
      value - The maximum number of iterations allowed for iterative calculation.
    • getMaximumChange

      double getMaximumChange()
      Gets the maximum error for iterative calculation.

      During iterative calculation, this value specifies the maximum difference allowed between the results of two consecutive iterations. Iteration stops when the difference is less than this value.

      
       workbook.getOptions().getFormulas().setMaximumChange(0.01d);
       double maximumChange = workbook.getOptions().getFormulas().getMaximumChange();
       
      Returns:
      The maximum error allowed for iterative calculation.
    • setMaximumChange

      void setMaximumChange(double value)
      Sets the maximum error for iterative calculation.

      During iterative calculation, this value specifies the maximum difference allowed between the results of two consecutive iterations. Iteration stops when the difference is less than this value.

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       formulaOptions.setMaximumChange(0.01d);
       
      Parameters:
      value - The maximum error allowed for iterative calculation.
    • getCalculationMode

      CalculationMode getCalculationMode()
      Gets the calculation mode stored in the exported workbook.

      This setting controls how Microsoft Excel recalculates formulas when the exported workbook is opened. It does not trigger calculation or control formula calculation in the current GcExcel workbook. To control calculation in the current workbook, use Workbook.setEnableCalculation(boolean).

      
       workbook.getOptions().getFormulas().setCalculationMode(CalculationMode.Manual);
       CalculationMode mode = workbook.getOptions().getFormulas().getCalculationMode();
       if (mode == CalculationMode.Manual) {
           workbook.save("path/to/manual-mode.xlsx");
       }
       
      Returns:
      The calculation mode stored in the exported workbook.
    • setCalculationMode

      void setCalculationMode(CalculationMode calculationMode)
      Sets the calculation mode stored in the exported workbook.

      This setting controls how Microsoft Excel recalculates formulas when the exported workbook is opened. It does not trigger calculation or control formula calculation in the current GcExcel workbook. To control calculation in the current workbook, use Workbook.setEnableCalculation(boolean).

      
       IFormulaOptions formulaOptions = workbook.getOptions().getFormulas();
       workbook.getActiveSheet().getRange("A1").setFormula("SUM(1, 2)");
       formulaOptions.setCalculationMode(CalculationMode.Manual);
       workbook.save("path/to/manual-mode.xlsx");
       
      Parameters:
      calculationMode - The calculation mode to store in the exported workbook. Must not be null.