Reputation: 115
I'm using PHPExcel library, I extract the content of a column cell, that cell has a date, in excel it is displayed as "30/07/2014" but when I extract it using the library it dispalyes : 41850 as date value, I can't rely on the excel formatting cells because each time I get a different file with date so my question is , is there a way to convert the value 41850 using the library to the original date text 30/07/2014?
The code I'm using is :
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$outPut = $objPHPExcel->getSheet(0)->getCellByColumnAndRow(6, 6)->getFormattedValue();
echo $outPut;//41850
Upvotes: 2
Views: 2446
Reputation: 212402
Your problem is
$objReader->setReadDataOnly(true);
You're telling PHPExcel only to read the raw data from the cell, without any formatting information; but MS Excel uses a float for dates (number of days since 1/1/1900 or since 1/1/1904, depending on the calendar used) and a number format mask to format it as a date.... by setting read data only to true, you're telling PHPExcel not to read the number format masks, so there is no way of differentiating a date value from any other float value.
Solution: don't use
$objReader->setReadDataOnly(true);
Upvotes: 1