I am trying to print Excel file data on a page. For this I used PHPExcel lib, everything works well, in addition to printing formulas, I have a simple example with such a formula=SUM(C2:C5)
=SUM(C2:C5)
I print the values this way:
$val = $cell->getValue(); echo '<td>' . $val . '</td>';
how can i check if $ val is a formula?
PHPExcel_Cell_DataType::dataTypeForValue($val); told me it was just another line in my $val
PHPExcel_Cell_DataType::dataTypeForValue($val);
$val
Ofc, I can calculate it in a loop, and chek, if this is the last line, insert the necessary information with my hands, but how can I calculate it in a simple way?
We look forward to hearing your advice. Thank.
PHPExcel_Cell_DataType::dataTypeForValue($val); , . , . getDataType() 'f' .
getDataType()
'f'
getCalculatedValue(), getValue(), PHPExcel , . , , , getValue();. , , - getFormattedValue(), , . . , . , , .
getCalculatedValue()
getValue()
getValue();
getFormattedValue()
toArray() rangeToArray(), , . , , .
toArray()
rangeToArray()
" , $val ?"
excel = :
=
<?php $String = 'SUM(B3:B8)'; # See http://www.php.net/manual/en/language.types.string.php # $String{} is deprecated as of PHP 6. if($String[0] == '='){ echo 'Yes'; } else { echo 'No'; } ?>
<?php function IsExcelFormula($String=null){ if(!$String OR strlen($String) <= 0){ return false; } $First = $String[0]; return ($First == '=' ? true : false); } var_dump(IsExcelFormula('=SUM(B8:B9)')); // bool(true) var_dump(IsExcelFormula('TOTAL(B3:B6)')); // bool(false) ?>