SpreadsheetGear The Performance Spreadsheet Component Company 
Formula Property
See Also  Example
SpreadsheetGear Namespace > IRange Interface : Formula Property
Gets or sets the value or formula of the cells represented by this IRange.

Syntax

C# 
virtual string Formula {get; set;}

Example

C#Copy Code
// Set cells to a formula which referes to the top-left cell in the worksheet. 
range.Formula = "=$A$1"; 
  
// Set cells to a formula for Pi. 
range.Formula = "=PI()"; 
  
// Set cells to the text "Hello World!". 
range.Formula = "Hello World!"; 
  
// Set cells to the number 123.5. 
range.Formula = "123.5"; 
  
// Set cells to the number represented by the date "4/20/2005" and format the cell as a date. 
range.Formula = "4/20/2005"; 
  
// Set cells to the logical value TRUE. 
range.Formula = "True"; 
  
// Set cells to the error value #N/A. 
range.Formula = "#n/a";
Visual BasicCopy Code
' Set cells to a formula which referes to the top-left cell in the worksheet.
range.Formula = "=$A$1"

' Set cells to a formula for Pi.
range.Formula = "=PI()"

' Set cells to the text "Hello World!".
range.Formula = "Hello World!"

' Set cells to the number 123.5.
range.Formula = "123.5"

' Set cells to the number represented by the date "4/20/2005" and format the cell as a date.
range.Formula = "4/20/2005"

' Set cells to the logical value TRUE.
range.Formula = "True"

' Set cells to the error value #N/A.
range.Formula = "#n/a"

Remarks

To put a formula in a cell, the first character must be '='. Otherwise, attempts will be made to convert the specified string to a number, date, time, date/time, logical or error value. If none of these succeed, the value will be set in the cell as text.

When a value is converted from a string to a number, an appropriate number format is applied to the cell. For example, setting Formula to "10%" sets the value of the cell to 0.1 and sets the number format of the cell to "0%". The number format of the cell will not be changed unless it is a different type, such as putting "5%" into a cell currently formatted as currency.

The System.Globalization.CultureInfo of the current workbook set is used to determine how to parse dates, times, numbers and currency values.

Requirements

Platforms: Windows 98, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family. SpreadsheetGear for .NET 1.x requires the Microsoft .NET Framework 1.1 or .NET 2.0. SpreadsheetGear for .NET 2006 requires the Microsoft .NET Framework 2.0.

See Also