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

StackOverflow https://stackoverflow.com/questions/6817145

  •  25-10-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top