Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Cell Data Types

  • 5 minutes to read

A CellValue object specifies the value for each cell in a worksheet. To access the cell value object, use the CellRange.Value property. The data within the cell defines the cell value:

The following cell value types are available:

Cell values can have various display formats. For example, you can display a numeric value as a decimal number, a percentage or currency value, a date or time value, and so on.

Use the CellRange.Value property to retrieve the cell value. The Value property returns a CellValue object that provides APIs to determine the cell’s value type and retrieve the value as an object of the corresponding type.

To get the string that specifies the formatted value as it is displayed in a cell, use the Cell.DisplayText property.

#Empty

Empty is the default cell value type. If a cell is empty, the CellValue.IsEmpty property returns true, and the CellValue.Type property returns CellValueType.None.

If a cell contains any data and you want make the cell empty, set the CellRange.Value property to null or CellValue.Empty:

Spreadsheet_EmptyValue

cell.Value = null;
cell.Value = CellValue.Empty;

#Numeric

The type of a cell is considered numeric if the cell’s Value is a value of any numeric type (for example, Int32, Double, and so on) or the cell’s Formula property value is an expression that returns a number.

cell.Value = 12345678;
cell.Formula = "= SUM(12000000,345678)";

For cells with numeric data, the CellValue.IsNumeric property returns true and the CellValue.Type returns CellValueType.Numeric.

To get the cell value as a numeric, use the CellValue.NumericValue property.

Use the NumberFormat property to change the display format for a numeric cell:

Spreadsheet_NumericValue

cell.NumberFormat = "#,#";

See the following page for information about number formatting rules: Review guidelines for customizing a number format.

For more examples, refer to the following help topics:

#Numeric (Date and Time)

For date-time cells, the cell’s Value property can contain one of the following values:

cell.Value = new DateTime(2012, 12, 10);

workbook.DocumentSettings.Calculation.Use1904DateSystem = true;
cell.Value = CellValue.FromDateTime(new DateTime(2012, 12, 10), true);

cell.Value = 41253;
cell.Formula = "=DATE(2012,12,10)";

Use the NumberFormat property to change the display format for a date-time cell:

Spreadsheet_NumericValue_DateTime

cell.NumberFormat = "m/d/yy";

See the following page for information about date-time formatting rules: Review guidelines for customizing a number format (Guidelines for date and time formats)

For cell with dates and times, CellValue.IsNumeric and CellValue.IsDateTime properties return true and the CellValue.Type property returns CellValueType.DateTime.

To obtain the date-time cell value, use CellValue.DateTimeValue or CellValue.NumericValue (returns a serial number for the corresponding date-time value).

Refer to the following help topics for more information about date-time cell values:

#Text

Text cells contain a String object or a Formula that results to a string value:

cell.Value = "Sample Text";
cell.Formula = "= PROPER("sample text")";

Spreadsheet_TextValue

For cells with text data, the CellValue.IsText property returns true and the CellValue.Type property returns CellValueType.Text.

To obtain the text assigned to a cell, use the CellValue.TextValue property.

#Boolean

Boolean cells contain a Boolean object or a Formula that results to TRUE or FALSE:

Spreadsheet_BooleanValue

cell.Value = true;

cell.Formula = "= TRUE()";

For cells with Boolean data, the CellValue.IsBoolean property returns true and the CellValue.Type property returns CellValueType.Boolean.

To obtain the data value assigned to a cell, use the CellValue.BooleanValue property.

#Error

An error cell’s Value property can contain one of the following values:

  • An object that the CellValue.Error* field (for example, CellValue.ErrorDivisionByZero). For more information about possible error types, refer to the following help topic: Error Types.
  • The cell’s Formula property value is an error code (for example, “=#DIV/0!”, “=#N/A”, and so on.)
  • An expression that cannot be calculated correctly (for example, an expression that contains an invalid function name, value, division by zero, and so on)

Spreadsheet_ErrorValue

cell.Value = CellValue.ErrorDivisionByZero;
cell.Formula = "= #DIV/0!";
cell.Formula = "=5/0";

For cells with errors, the CellValue.IsError property returns true and the CellValue.Type property returns CellValueType.Error.

To obtain the error assigned to a cell, use the CellValue.ErrorValue property.

#Image

The Value property of image cells contains images.

Spreadsheet Image Cell Value

cell.Value = File.ReadAllBytes("image.png");
cell.Value = new MemoryStream(imageBytes);

For cells with images, the CellValue.IsCellImage property returns true and the CellValue.Type property returns CellValueType.CellImage.

To obtain the image assigned to a cell, use the CellValue.ImageValue property.

For more information, refer to the following help topic: How to: Place a Picture in a Cell.

See Also