Spread Windows Forms 18
Spread Windows Forms 18 Product Documentation / Developer's Guide / Formulas in Cells / Recalculating and Updating Formulas Automatically
In This Topic
    Recalculating and Updating Formulas Automatically
    In This Topic

    By default, the spreadsheet recalculates formulas in the spreadsheet when the contents of dependent cells change. You can turn this recalculation off. You can also recalculate an individual cell.

    Also by default, the spreadsheet updates formulas when you add, insert, or remove columns or rows or when you move or swap blocks of cells. You can turn off these automatic formula updates, but generally you probably want the spreadsheet to update formulas in these cases. Keep in mind how turning off automatic formula updating might impact the spreadsheet if the user moves data, adds rows or columns, or performs other actions that affect the location of data.

    When automatic formula updating is on, the spreadsheet updates absolute and relative cell references, as follows:

    Use the AutoCalculation property to turn on or off the automatic recalculation of formulas. Use the Recalculate method for recalculating formulas.

    Using Code

    1. If needed, set the reference style for the sheet with the ReferenceStyle property.
    2. Add a formula to the cell with the SetFormula method.
    3. Set the Recalculate method to recalculate.

    Example

    This example recalculates all the formulas.

    C#
    Copy Code
    fpSpread1.ActiveSheet.SetValue(0, 0, 20);
    fpSpread1.ActiveSheet.SetValue(0, 1, 10);
    fpSpread1.ActiveSheet.SetFormula(3, 0, "SUM(A1,B1)");
    fpSpread1.ActiveSheet.SetFormula(4, 0, "A1*B1");
    fpSpread1.ActiveSheet.SetValue(0, 1, 100);
    fpSpread1.ActiveSheet.Recalculate();
    
    VB
    Copy Code
    fpSpread1.ActiveSheet.SetValue(0, 0, 20)
    fpSpread1.ActiveSheet.SetValue(0, 1, 10)
    fpSpread1.ActiveSheet.SetFormula(3, 0, "SUM(A1,B1)")
    fpSpread1.ActiveSheet.SetFormula(4, 0, "A1*B1")
    fpSpread1.ActiveSheet.SetValue(0, 1, 100)
    fpSpread1.ActiveSheet.Recalculate()
    
    See Also