Excel Formulas in C#
Use IronXL to set formulas, evaluate and retrieve calculated output values without Office Interop. IronXL supported over 150+ formulas and increasing with each new implementation. Formula can be set with
Range.Formula
property. For example,
workSheet ["A2"].Formula = "=SQRT(A1)"
workSheet ["B8"].Formula = "=C9/C11"
workSheet ["G31"].Formula = "=TAN(G30)"
workSheet ["A2"].Formula = "=SQRT(A1)"
workSheet ["B8"].Formula = "=C9/C11"
workSheet ["G31"].Formula = "=TAN(G30)"
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'workSheet ["A2"].Formula = "=SQRT(A1)" workSheet ["B8"].Formula = "=C9/C11" workSheet ["G31"].Formula = "=TAN(G30)"
A formula is an expression which calculates the value of a cell. Functions are predefined formulas and are already available in Excel.
IronXL is fairly unique in .NET Excel libraries in that it supports a wide range of Excel formulas and can calculate formula values in real time.
How to Use Excel Formulas in C#
- Install an Excel library to use Excel formula.
- Load the Excel document and select the default
Worksheet
- Set formulas and values to desired spreadsheet cells.
- Use
EvaluateAll
to calculate the applied formulas. - Save the
Workbook
object to an Excel file