0

大家好 :D 谢谢大家看一看,非常感谢。

这是一个 PHPExcel 问题。我在 Excel 文件中有A1=-1, B2=A2=0,所以B2应该返回“FALSE”。但是,当尝试通过 检索它时getCalculatedValue,它返回空白。

echo $objPHPExcel->getActiveSheet()->getCell('B2')->getCalculatedValue();

对于那些感兴趣的人,整个代码在这里。

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

/** Load Excel File **/
$inputFileName = './TrueFalse.xlsx';
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);

/** Change A2 Value **/
$objPHPExcel->getActiveSheet()->setCellValue('A2','=-1');

/** Calculate and State B2 Value **/
echo '<br><br> Show Calculated Value for B2';
echo '<br> B2 = ';
echo $objPHPExcel->getActiveSheet()->getCell('B2')->getCalculatedValue();
4

1 回答 1

1

a PHP echo statement will display nothing for a FALSE value. Either use

var_dump($objPHPExcel->getActiveSheet()->getCell('B2')->getCalculatedValue());

though var_dump should normally only be used for debugging; or something like:

echo $objPHPExcel->getActiveSheet()->getCell('B2')->getCalculatedValue() ? 'TRUE' : 'FALSE';
于 2013-04-15T10:01:13.937 回答