Version

Adding a Formula to a Cell (Infragistics Excel Engine)

The Infragistics Excel Engine allows you to add Microsoft® Excel® formulas to a cell or group of cells in a worksheet. You can do this using the WorksheetCell object’s ApplyFormula method or by instantiating a Formula object and applying it to a cell. Regardless of the manner in which you apply a formula to a cell, you can access the Formula object using the WorksheetCell object’s Formula property. If you need the value, use the cell’s Value property.

The following code shows you how to add a formula to a cell. The example code assumes you have a reference to a Worksheet object named worksheet1.

In Visual Basic:

worksheet1.Rows(5).Cells(0).ApplyFormula("=Sum(A1:A5)")
'Using a Formula object to apply a formula
Dim sumFormula As Formula = Formula.Parse("=Sum(A1:A5)")
sumFormula.ApplyTo(worksheet1.Rows(5).Cells(0))

In C#:

worksheet1.Rows[5].Cells[0].ApplyFormula("=Sum(A1:A5)");
//Using a Formula object to apply a formula
Formula sumFormula = Formula.Parse("=Sum(A1:A5)");
sumFormula.ApplyTo(worksheet1.Rows[5].Cells[0]);