SpreadsheetGear 2017
Formula Property (IRange)
Example 






SpreadsheetGear Namespace > IRange Interface : Formula Property
Gets the formula, or sets the value or formula, of the cells represented by this IRange.
Syntax
'Declaration
 
Property Formula As System.String
'Usage
 
Dim instance As IRange
Dim value As System.String
 
instance.Formula = value
 
value = instance.Formula
System.string Formula {get; set;}
read-write property Formula: System.String; 
function get,set Formula : System.String
__property System.string* get_Formula();
__property void set_Formula( 
   System.string* value
);
property System.String^ Formula {
   System.String^ get();
   void set (    System.String^ value);
}

Property Value

Returns the formula of the cell represented by this IRange.
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.

Example
// 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";
' 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"
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IRange Interface
IRange Members
FormulaArray Property
FormulaR1C1 Property
Value Property
ValueType Property
Text Property
Entry Property
GetWorkbookSet(CultureInfo) Method