Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.2
  • 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 that cell value:

    • If the cell does not contain any data, cell value is empty (CellValue.IsEmpty is set to true).
    • If a constant is assigned to the Cell.Value property, cell value is not calculated or changed.
    • If cell value is the result of a calculation from a formula assigned to that cell by the CellRange.Formula property, cell value is calculated dynamically.

    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 Cell.Value property to retrieve cell value. The Value property returns a CellValue object that provides APIs to determine that cell’s value type and retrieve the value as an object of the corresponding type.

    Empty

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

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

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

    Spreadsheet_EmptyValue

    using DevExpress.Docs.Spreadsheet;
    
    cell.Value = null;
    cell.Value = CellValue.Empty;
    

    Numeric

    The type of a cell is considered numeric if its Value is of a 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.Type property returns CellValueType.Numeric.

    To format a cell to have a numeric value, use the CellValue.NumericValue property.

    Use the CellFormat.NumberFormat property to change the display format for a numeric cell. For additional information about formatting numeric values, refer to the following help topic: Set Number and Date Formats.

    Date and Time

    Cells store dates and times as serial numbers. The integer part of a serial number specifies the date, and the fractional part specifies the time of day. For example, the serial number 46314.5 is October 19, 2026, 12:00 PM in the 1900 date system. The cell number format specifies how the cell displays the serial number.

    Call the Cell.SetDateValue(value) method to assign a DateTime value to a cell. The SetDateValue method converts the date to a serial number, and the CellValue.Type property gets CellValueType.Numeric.

    To assign a date and specify the display format (for example, a time format), call the Cell.SetDateValue(value, format) method.

    Call the Cell.GetDateValue() method to retrieve a numeric cell value as a DateTime value. The GetDateValue method does not check the cell number format. If the cell value is not numeric, the GetDateValue method throws an InvalidOperationException.

    If a cell contains a formula, call the Workbook.Calculate() method before you call the GetDateValue method. Otherwise, the GetDateValue method throws an InvalidOperationException. For additional information about formula calculation, refer to the following help topic: Calculate Formulas.

    The following code snippet assigns dates to cells A1 and A2, adds a formula to cell A3 that adds one month to the A2 date, and retrieves the formula result:

    worksheet.Cells["A1"].SetDateValue(new DateTime(2026, 10, 19, 14, 30, 0));
    worksheet.Cells["A2"].SetDateValue(new DateTime(2026, 10, 19), new NumberFormat("yyyy-mm-dd"));
    
    worksheet.Cells["A3"].Formula = "=EDATE(A2,1)";
    workbook.Calculate();
    DateTime nextMonth = worksheet.Cells["A3"].GetDateValue();
    

    Refer to the following help topic for additional information about date and time formats: Set Number and Date Formats.

    Date Systems

    The workbook date system specifies serial numbers of dates. Use the CalculationOptions.Use1904DateSystem property to specify the date system. SetDateValue and GetDateValue methods convert dates based on the workbook date system.

    The 1900 date system supports dates from January 1, 1900. The 1904 date system supports dates from January 1, 1904. If you pass an earlier date, the SetDateValue method throws an ArgumentOutOfRangeException.

    Text

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

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

    Spreadsheet_TextValue

    For cells with text data, CellValue.Type property returns CellValueType.Text.

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

    For information about how to apply rich text formatting to cell text, refer to the following help topic: Apply Rich Text Formatting to Cell Text

    Boolean

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

    Spreadsheet_BooleanValue

    cell.Value = true;
    cell.Formula = "=TRUE()";
    

    For cells with Boolean data, 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:

    • The cell’s Value property is set to the value returned by the CellValue.FromError(SpreadsheetError) method.
    • 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.FromError(SpreadsheetError.DivisionByZero);
    cell.Formula = "= #DIV/0!";
    cell.Formula = "=5/0";
    

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

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

    Refer to the following help topic for more information on possible errors in cells: Cell Error Values.