Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel - read time value from a cell

Tags:

php

phpexcel

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)

like image 769
kolufild Avatar asked Dec 08 '11 13:12

kolufild


1 Answers

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;
like image 139
matino Avatar answered Oct 26 '22 16:10

matino