10

I'm loading an Excel file that has cells with time data, e.g. 08:00:00. But when I try to read those cells with getValue(), it returns some floating point numbers instead of the actual time (in case of 08:00:00, it returns 0.3333333). Here's my code:

 $objPHPExcel = PHPExcel_IOFactory::load($filename);
 $objWorksheet = $objPHPExcel->getActiveSheet();
 echo $objWorksheet->getCellByColumnAndRow(3, 5)->getValue();

How do I bypass this weird conversion?

PHPExcel 1.7.6 and Excel 2003 Worksheet (.xls)

pnuts
  • 58,317
  • 11
  • 87
  • 139
kolufild
  • 712
  • 1
  • 9
  • 20

1 Answers1

19

You need to apply cell format for this:

$cell = $objWorksheet->getCellByColumnAndRow(3, 5);
$cell_value = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'hh:mm:ss');
echo $cell_value;
matino
  • 17,199
  • 8
  • 49
  • 58