SpreadsheetGear Namespace > IRange Interface : Formula Property (IRange) |
Gets or sets the value or formula of the cells represented by this IRange.
[Visual Basic]
Overridable Property Formula As String
[C#]
virtual string Formula {get; set;}
[C++]
__property virtual string * get_Formula();
__property virtual void set_Formula(
string * value
);
[C++/CLI]
virtual property String ^ Formula {
String ^ get();
void set (String ^ value);
}
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.
[C#]
// 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 Basic]
' 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"
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
IRange Interface | IRange Members | FormulaArray Property | FormulaR1C1 Property | Value Property | ValueType Property | Text Property | Entry Property | GetWorkbookSet(CultureInfo) Method
See our live Excel Reporting, Excel Charting, Excel to DataGrid and Excel Calculation Samples.
Copyright © 2003-2007 SpreadsheetGear LLC. All Rights Reserved.
SpreadsheetGear and Spreadsheet Gear are trademarks of SpreadsheetGear LLC.