SpreadsheetGear
Formula Property
See Also  Example Send Feedback
SpreadsheetGear Namespace > IRange Interface : Formula Property

Gets the formula, or sets the value or formula, of the cells represented by this IRange.

Syntax

Visual Basic (Declaration) 
Property Formula As String
C# 
string Formula {get; set;}

Return Value

Returns the formula of the cell represented by this IRange.

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 text "66044" without parsing by using a leading single quote.
range.Formula = "'66044";

// 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 text "66044" without parsing by using a leading single quote.
range.Formula = "'66044"

' 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.

To put text in a cell without attempting to parse the string, use a leading single quote. Setting a cell to "'66044" will place the text "66044" into the cell without any parsing.

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.

Use Value to get the value of the cell represented by this IRange or use Text to get the formatted value of the cell.

Requirements

Platforms: Windows 2000, Windows XP, Windows Vista, Windows Server 2003 and Windows Server 2008. SpreadsheetGear 2008 requires the Microsoft .NET Framework 2.0 and supports .NET 3.0 and .NET 3.5.

See Also

Copyright © 2003-2009 SpreadsheetGear LLC. All Rights Reserved.Help Powered by Innovasys   
SpreadsheetGear is a registered trademark of SpreadsheetGear LLC.
Microsoft, Microsoft Excel and Visual Studio are trademarks or registered trademarks of Microsoft Corporation.