CalculationOptions Class
Class represents various calculation engine options.
- Inheritance:
- CalculationOptions
Properties
CultureInfo
Gets or sets the culture used during the calculation.
The default value is CurrentCulture.
Property Value
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 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
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
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
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
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 Decimal values instead of Double values for increased precision, at the expense of performance.
public bool ResolveMathFunctionsWithDecimalType { get; set; }
Public Property ResolveMathFunctionsWithDecimalType As Boolean
Property Value
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 Double is actually 78.974999999999994315658113919198513031005859375.
Calling Round(Decimal, Int32, MidpointRounding) with (Double)78.975, 2 and AwayFromZero will result in 78.97, which is incorrect.
Calling Round(Decimal, Int32, MidpointRounding) with (Decimal)78.975, 2 and 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.