Spread for WinForms allows you to display and highlight the formula in a cell instead of its final calculated value. The DisplayFormulas property in the IWorksheetView interface is used to enable or disable the display and highlight of cell formulas. By default, it is set to false. The DisplayFormulas property is set at the worksheet level. Hence, the other worksheets are not impacted by the value of any particular sheet.
When the DisplayFormulas property is set to true, then the cell’s formula is highlighted, and the column widths are also doubled to display the long formulas in cells conveniently. However, when set to false, the column widths are restored to their original width.
Note:
The below image depicts the behavior of the DisplayFormulas property-
The following code is used to display and highlight the formula in the active cell.
C# |
Copy Code
|
---|---|
IWorksheet sheet = fpSpread1.AsWorkbook().ActiveSheet; // Displaying formula in cell sheet.View.DisplayFormulas = true; sheet.Cells["A1"].Value = 1; sheet.Cells["B1"].Value = 1; sheet.Cells["A2"].Formula = "SUM(A1,B1)"; sheet.Cells["A2"].Select(); |
Visual Basic |
Copy Code
|
---|---|
Dim sheet As IWorksheet = FpSpread1.AsWorkbook().ActiveSheet ' Displaying formula in cell sheet.View.DisplayFormulas = True sheet.Cells("A1").Value = 1 sheet.Cells("B1").Value = 1 sheet.Cells("A2").Formula = "SUM(A1,B1)" sheet.Cells("A2").[Select]() |
To enable the 'Show Formulas' option in Spread Designer, click on the 'Show Formulas' button from the Formulas tab. If the mode is already enabled, this button turns gray.