Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Adding a formula to a cell is just like setting the value of a cell as we discussed in our previous topic: Accessing & Modifying the Value of a Cell except that in that case, we only added simple values to cells. Now, we will add formulas. Developers can use the Value property of a cell to access and modify the formula, or they can use the SetCellValue method of the cell to add or modify the formula.
IMPORTANT: The basic difference between using the Value property or the SetCellValue method of a cell is that the Value property invokes the RunAllFormulas method of Grid automatically to recalculate the values of all formulas, whereas in the case of the SetCellValue method developers need to call RunAllFormulas explicitly after the formulas are added to cells. Actually, when we use SetCellValue, this method sets the value of the cell to FormulaType only and does not calculate the formula. Moreover, calling RunAllFormulas every time is not necessary. If you want to add many formulas in the cells of a worksheet, you can call RunAllFormulas just once at the end.
A formula is added to a cell as a string value. Moreover, the formula structure must be compatible with the formula structure of MS Excel. All formulas must begin with an Equal Sign (=).
In the example given below, we have added a formula to multiply the values of two cells of the worksheet and store the result in another cell. The RunAllFormulas method is also invoked at the end.
Now run the application. If you double‑click on the cell where the formula was added, you will notice that the value is replaced by the formula that is actually calculating the value on the back end.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.