Based on https://ironsoftware.com/examples/excel-formulas-csharp/
Utilize IronXL to implement, evaluate, and acquire the computed values through formulas without the need for Office Interop. IronXL currently supports over 150+ formulas and that number continues to grow with each update. Formulas can be applied using the
Range.Formula property. For instance,
workSheet["A2"].Formula = "=SQRT(A1)"; // Calculates the square root of the value in cell A1
workSheet["B8"].Formula = "=C9/C11"; // Divides the value in cell C9 by the value in cell C11
workSheet["G31"].Formula = "=TAN(G30)"; // Computes the tangent of the angle in cell G30A formula is essentially an expression used to determine the value of a spreadsheet cell. Excel functions, which are predefined formulas, are readily accessible within Excel.
What distinguishes IronXL in the .NET Excel library landscape is its robust support for numerous Excel formulas and its ability to instantly compute formula outcomes.
- Begin by integrating an Excel library that supports formula functionality.
- Open the desired Excel file and access the default
Worksheet. - Assign the necessary formulas and values to the selected cells within your spreadsheet.
- Employ the
EvaluateAllmethod to compute all set formulas in the document. - Finally, store the changes by saving the
Workbookobject as an Excel file.