Cell Data Types
- 4 minutes to read
Each cell in a worksheet has a value that is specified by the CellValue object. To access this object, use the CellRange.Value property. A cell value is determined by the data contained within the cell:
- If the cell does not contain any data, the cell value is empty (CellValue.IsEmpty is set to true). Refer to the following example for more information: How to: Clear Cells of Content, Formatting, Hyperlinks and Comments.
- The cell value is determined by a constant assigned to the cell via the CellRange.Value property. In this case, the cell value is neither calculated nor changed.
- The cell value is determined by a value resulting from a formula assigned to a cell via the CellRange.Formula property. In this case, the cell value is calculated dynamically.
A cell value can be of one of the following types: empty, numeric, text, Boolean or error. Cell values may have various display formats. For example, a numeric value can be displayed as a decimal number, a percentage or currency value, a date or time value, etc.
Use the properties of the CellValue object returned by the CellRange.Value property to retrieve information about the cell value type, and get the cell value itself as an object of the corresponding type. To get the string specifying the formatted value as it is displayed in a cell, use the Cell.DisplayText property.
The table below lists the available cell value types and provides examples on how a value of each type can be input, formatted, displayed and obtained.
Cell Value Type | Cell Content | Sample Input | Sample Display Format | Displayed String (Cell. |
Cell Type API | Cell Value API | More Examples |
---|---|---|---|---|---|---|---|
Empty | The default cell value type. If a cell contains any data, you can assign an empty value to it by setting the Cell |
cell. cell. |
![]() |
Cell |
Cell |
How to: Clear Cells of Content, Formatting, Hyperlinks and Comments | |
Numeric | The cell’s Cell |
cell. cell. |
cell. |
![]() |
Cell |
Cell |
How to: Specify Number or Date Format for Cell Content |
Numeric (Date and Time) | The cell’s Cell The cell’s Cell |
cell. workbook. cell. cell. cell. |
cell. |
![]() |
Cell |
Cell |
Dates and Times in Cells How to: Specify Number or Date Format for Cell Content |
Text | The cell’s Cell |
cell. cell. |
![]() |
Cell Cell |
Cell |
||
Boolean | The cell’s Cell |
cell. cell. |
![]() |
Cell Cell |
Cell |
||
Error | The cell’s Cell The cell’s Cell |
cell. cell. cell. |
![]() |
Cell Cell |
Cell |
Error Types | |
Image | The cell’s Value property is assigned to an image | cell. cell. cell. |
![]() |
Cell Cell |
Cell |
How to: Place a Picture in a Cell |