CalculationOptions Class
Class represents various calculation engine options.
- Inheritance:
- System.ObjectCalculationOptions
Properties
CalculationMode
Gets or sets the calculation mode.
public CalculationMode CalculationMode { get; set; }
Public Property CalculationMode As CalculationMode
Property Value
The calculation mode.
Remarks
The property has no effect on the calculation performed by one of the Calculate() methods.
CultureInfo
Gets or sets the culture used during the calculation.
The default value is System.Globalization.CultureInfo.CurrentCulture.
Property Value
- System.Globalization.CultureInfo
The culture used during the calculation.
Remarks
important
.NET 5.0 and later versions use International Components for Unicode (ICU) libraries for globalization functionality when running on Windows 10 May 2019 Update or later.
When running your application on .NET 5.0, you might see changes in calculation of some formulas, for example, when formatting currency (if CultureInfo is specified without country or region) or negative currency (because System.Globalization.NumberFormatInfo.CurrencyNegativePattern might differ between ICU and NLS which is used on .NET Framework and .NET Core 3.1 and lower).
For more information about this .NET 5.0 breaking change and how to revert to using NLS globalization APIs, see the Globalization APIs use ICU libraries on Windows page.
EnableCaching
Gets or sets the value indicating whether the intermediate results of formulas should be cached. For some files, caching can decrease the time necessary to calculate formulas.
Property Value
- System.Boolean
The value indicates whether the intermediate results of formulas should be cached. The default value is false.
Remarks
Use this property with caution, however. For most files, caching will not improve performance, but hurt it. Caching is useful only when there are repeated formulas (or expressions) that are always evaluated to the same result. So, even though some formulas can look the same, their results will be different; Thus, they are inapplicable for caching. An example of such a formula is
=MAX(ROW(), COLUMN())
, whose result will not be cached, because the result depends on the cell where the formula is placed.EnableIterativeCalculation
Gets or sets a value indicating whether iterative calculation is enabled.
public bool EnableIterativeCalculation { get; set; }
Public Property EnableIterativeCalculation As Boolean
Property Value
- System.Boolean
True
if iterative calculation is enabled; otherwise, false
.
Remarks
A circular reference is when a formula refers to itself directly or indirectly. Setting this property to true
will allow circular references in cell formulas; otherwise a SpreadsheetParserException will be thrown for every circular reference in the calculation process.
MaximumChange
Gets or sets the maximum calculation change.
Property Value
- System.Double
The maximum calculation change.
Remarks
This property defines the maximum value change in circular reference iterations after which the calculation process is stopped.
MaximumIterations
Gets or sets the maximum calculation iterations.
Property Value
- System.Int32
The maximum calculation iterations.
Remarks
This property defines the maximum number of formula recalculations for a circular reference.
ResolveMathFunctionsWithDecimalType
Gets or sets a value indicating whether mathematical operations should be resolved using System.Decimal values instead of System.Double values for increased precision, at the expense of performance.
public bool ResolveMathFunctionsWithDecimalType { get; set; }
Public Property ResolveMathFunctionsWithDecimalType As Boolean
Property Value
- System.Boolean
True
if mathematical operations should be resolved using decimal values; otherwise, false
.
Remarks
The double type can on some rare occasions not be precise enough to represent a number correctly, for example, 78.975 as a System.Double is actually 78.974999999999994315658113919198513031005859375.
Calling System.Math.Round(System.Decimal,System.Int32,System.MidpointRounding) with (System.Double)78.975, 2 and System.MidpointRounding.AwayFromZero will result in 78.97, which is incorrect.
Calling System.Math.Round(System.Decimal,System.Int32,System.MidpointRounding) with (System.Decimal)78.975, 2 and System.MidpointRounding.AwayFromZero will result in 78.98, which is correct.
If this option is set to true, mathematical operations that could trigger problems when used with double (for example, round) will be resolved with decimal, which can reduce performance.