Does anyone know how to detect the format of Excel cells using PHPExcel? One answer here How to know the formatting of Excel Cell did it in C#, but I want to do it with PHPExcel. Thanks.
1 Answers
2
votes
$objPHPExcel->getActiveSheet()
->getStyle('A1');
Will return the Style object for cell A1 in the current active worksheet. You can then look at the properties of the style object to identify the elements of style that you're interested in.
If it's specifically the number format, then
$objPHPExcel->getActiveSheet()
->getStyle('A1')
->getNumberFormat();
Will return the number format mask object, which has a getFormatCode()
method to return the format mask as a string
EDIT
If you specifically want to test if a cell contains a date format mask or not, then there's a special built-in function specifically written for this purpose:
if(PHPExcel_Shared_Date::isDateTime($objWorksheet->getCellByColumnAndRow($col, $row))) {
echo 'Cell contains a date or time';
}