How to get cell data type

Topics: Developer Forum
Nov 16, 2012 at 9:40 AM

Hi there, there is any way to get the data type of a cell (such as string, integer, date, etc...)?

Thanks in advance

Nov 18, 2012 at 2:38 PM

The cell object has a getDataType() method for this purpose. Valid return values are:

const TYPE_STRING2  = 'str';
const TYPE_STRING  = 's';
const TYPE_FORMULA  = 'f';
const TYPE_NUMERIC  = 'n';
const TYPE_BOOL   = 'b';
const TYPE_NULL   = 'null';
const TYPE_INLINE  = 'inlineStr'; // rich text string
const TYPE_ERROR  = 'e';

These are the datatypes recognised by Excel itself.

The differentiate between an integer and a float, retrieve the cell value and is PHP is_integer() or is_float() functions.

To differentiate between a number and a date, you need to use


(for the appropriate cell reference).

Nov 20, 2012 at 7:36 AM

Thank you Mark! You da one!