Back to Devexpress

Cell Data Types

aspnet-16165-components-spreadsheet-cell-basics-cell-data-types.md

latest3.7 KB
Original Source

Cell Data Types

  • Jan 09, 2025
  • 2 minutes to read

A cell value is stored in the CellValue object and can be accessed by the Cell.Value property. You can specify a value in two ways:

  • directly, by setting the Value property: cell.Value = 10;
  • as the result of a formula (Formula): cell.Formula = "= SUM(3,7)";

The Spreadsheet determines the type of the inserted/calculated data and sets the cell’s Type property value. Use the appropriate Value property to get the cell value.

The available cell value types are listed below.

|

Type

|

Identify the Type

|

Value

|

Sample Input

|

Display Text

| | --- | --- | --- | --- | --- | |

None

|

IsEmpty

|

|

cell.Value = null;

|

| |

Numeric

|

IsNumeric

|

NumericValue

|

cell.Value = 12345678;

cell.NumberFormat = "#,#";

|

12,345,678

| |

DateTime

|

IsDateTime

|

DateTimeValue

|

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

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

|

12/10/12

| |

Text

|

IsText

|

TextValue

|

cell.Value = "Sample Text";

|

Sample Text

| |

Boolean

|

IsBoolean

|

BooleanValue

|

cell.Value = true;

|

TRUE

| |

Error

|

IsError

|

ErrorValue

|

cell.Formula = "=5/0";

|

#DIV/0!

|

Note

ASPxSpreadsheet does not support embedded images.

Number Format

You can format Numeric and DateTime cell values. For instance, a number can appear in a cell as a percentage, decimal, currency, accounting, date or time value.

Assign a format pattern to the Cell.NumberFormat property to format a value in a cell. For more information, please review the following topic: How to: Specify Number or Date Format for Cell Content.

Use the Cell.DisplayText property to get the formatted value as it is displayed in a cell.

csharp
worksheet.Cells["A1"].Formula = "= Now()";
worksheet.Cells["A1"].NumberFormat = "m/d/yy h:mm";
// worksheet.Cells["A1"].DisplayText returns "5/20/2020 13:08"

worksheet.Cells["B1"].Value = 1.6;
worksheet.Cells["B1"].NumberFormat = "0.0%";
// worksheet.Cells["B1"].DisplayText returns "160.0%"

Online Demo

Cell Value