Skip to main content
A newer version of this page is available.
All docs
V17.2
Row

Range.Value Property

Gets or sets a cell value.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v17.2.Core.dll

Declaration

CellValue Value { get; set; }

Property Value

Type Description
CellValue

A CellValue object.

Remarks

A value contained in a cell is specified by the CellValue object. The Value property provides the access to this object.

To set a cell value, you can assign the Value property to an object of the String, DateTime, Boolean or any numeric type (e.g., Int32, Double, etc.). For detailed information on cell values and their types, see the Cell Data Types topic.

To use an object of any type for specifying a cell value, use the Range.SetValue method. It converts the passed object to the CellValue object using the default converter and assigns it to the cell. To use a custom converter instead of the default, use the CellValue.FromObject method. See the How to: Convert Objects to Cell Values and Cell Values to Objects example.

If a cell contains a formula, a cell value is dynamically calculated from that formula. If a cell does not contain any data, the Value property returns an empty value object (CellValue.IsEmpty is set to true).

Example

This example demonstrates how to add data of different types to worksheet cells. To do this, assign the required value to the Range.Value property of the cell or range object. This property returns the CellValue object, whose properties can be used to obtain the cell value type or get the value itself.

For details on how to access an individual cell or range of cells, refer to the How to: Access a Cell in a Worksheet or How to: Access a Range of Cells document.

Note

Note that a Decimal value cannot be assigned to a cell via the Range.Value property. Use the Range.SetValue or CellValue.FromObject method instead.

// Add data of different types to cells.
worksheet.Cells["B1"].Value = DateTime.Now;
worksheet.Cells["B2"].Value = Math.PI;
worksheet.Cells["B3"].Value = "Have a nice day!";
worksheet.Cells["B4"].Value = CellValue.ErrorReference;
worksheet.Cells["B5"].Value = true;
worksheet.Cells["B6"].Value = float.MaxValue;
worksheet.Cells["B7"].Value = 'a';
worksheet.Cells["B8"].Value = Int32.MaxValue;

// Fill all cells in the range with 10.
worksheet.Range["B10:E10"].Value = 10;

The following code snippets (auto-collected from DevExpress Examples) contain references to the Value property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also