[]
Evaluates the specified Excel formula or named expression and returns the result.
The formula is evaluated by using non-dynamic array semantics.
object Evaluate(string formula)
Function Evaluate(formula As String) As Object
| Type | Name | Description |
|---|---|---|
| string | formula | A string containing an Excel formula, named range, or defined name to evaluate. A leading |
| Type | Description |
|---|---|
| object | The evaluated result. If the formula result is a reference, such as |
worksheet.Range["A1"].Value = 100;
object result = worksheet.Evaluate("=A1*2");
| Type | Condition |
|---|---|
| InvalidFormulaException | if |
Evaluates the specified Excel formula or named expression by using a custom formula resolver and returns the result.
Use the resolver to supply values for custom names referenced by the formula. The calculation behavior is consistent with Excel 2019 and earlier versions.
object Evaluate(string formula, IFormulaResolver resolver)
Function Evaluate(formula As String, resolver As IFormulaResolver) As Object
| Type | Name | Description |
|---|---|---|
| string | formula | A string containing an Excel formula, named range, or defined name to evaluate. A leading |
| IFormulaResolver | resolver | The custom resolver used to resolve names referenced by the formula. If |
| Type | Description |
|---|---|
| object | The result of the evaluation. Returns an IRange object when the formula result is a reference, such as |
class CustomFormulaResolver : IFormulaResolver
{
public bool IsCustomName(string text)
{
return text == "TaxRate";
}
public object Evaluate(string text)
{
return text == "TaxRate" ? 0.08 : null;
}
}
IFormulaResolver resolver = new CustomFormulaResolver();
object result = worksheet.Evaluate("=100*TaxRate", resolver);
| Type | Condition |
|---|---|
| InvalidFormulaException | if |