开发者

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

开发者 https://www.devze.com 2023-03-23 05:48 出处:网络
I want to know how to read the visible/cal开发者_C百科culated contents of the cells of an Excel Sheet & not the underlying formula.

I want to know how to read the visible/cal开发者_C百科culated 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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消