Spread WPF 18
Features / Formulas and Functions / Add a Formula Bar
In This Topic
    Add a Formula Bar
    In This Topic

    You can enhance the GcSpreadSheet component by adding a formula bar, enabling seamless interaction with various formulas and functions by associating it with a worksheet. To integrate and use the GcFormulaBar, follow the steps outlined in the Quick Start to effectively connect the two components.

    The image below demonstrates how the GcFormulaBar integrates with the GcSpreadSheet component. The formula bar shows the formula applied to the cell range B2:B6, providing a clear visual representation of the formula in action.

     

    Refer to the following example code to add a formula bar with the GcSpreadSheet component and use the SUM formula to calculate the total sales.

    XAML
    Copy Code
    <Grid>
        <gss:GcFormulaBar HorizontalAlignment="Left" Margin="10,19,0,0" VerticalAlignment="Top" ShowEditingButtons="True" Expandable="True" AssociatedSpread="{x:Reference Name=spreadSheet1}"/>
        <gss:GcSpreadSheet Name="spreadSheet1" HorizontalAlignment="Center" Margin="10,50,0,0" VerticalAlignment="top"/>
    </Grid>
    
    Copy Code
    // Add SUM formula to get the total sales.
    spreadSheet1.Workbook.ActiveSheet.Cells["B8"].Text = "Total Sales:";
    spreadSheet1.Workbook.ActiveSheet.Cells["C8"].Formula = "SUM(B2:B6)";
    spreadSheet1.Workbook.ActiveSheet.Cells["C8"].Activate();
    
    Copy Code
    ' Add SUM formula to get the total sales.
    spreadSheet1.Workbook.ActiveSheet.Cells("B8").Text = "Total Sales:"
    spreadSheet1.Workbook.ActiveSheet.Cells("C8").Formula = "SUM(B2:B6)"
    spreadSheet1.Workbook.ActiveSheet.Cells("C8").Activate()