Viral Jain
Viral Jain

Reputation: 1014

How to read the visible data of the cell, not the underlying formula in PHPExcel?

I want to know how to read the visible/calculated contents of the cells of an Excel Sheet & not the underlying formula. For example:- if a cell contains sum(a1,a5) which equals say 123, then it shud read 123, not sum(a1,a5). Similarly for time, it shud read the time as it is, n not the referential value in ratio of 24:00:00...

Please help me out!!!

Viral Jain

Upvotes: 5

Views: 1574

Answers (2)

pancy1
pancy1

Reputation: 501

If you are unsure about the content of a cell (value or formula included), I recommend you to primarily do a check if the cell has a formula and then copy - paste accordingly. getOldCalculatedValue() is very helpful in this case. Here is an example of that:

$code = $sheet->getCell('A'.$y)->getValue();
if(strstr($code,'=')==true)
{
    $code = $sheet->getCell('A'.$y)->getOldCalculatedValue();
}
$objPHPExcel4->setActiveSheetIndex(0)
             ->setCellValue('A'.$l, $code);

For large data sets, getCalculatedValue() function is really cumbersome and lots of memory will be required to perform correctly.

Upvotes: 0

JMax
JMax

Reputation: 26591

You can use ...->getCell($columnAsLetters.$row)->getCalculatedValue(); as described in this thread: How to automatically read in calculated values with PHPExcel?

Upvotes: 4

Related Questions