我有一个PHP代码,它将MySQL中的数据集输入到我创建的Excel模板中的列中。 Excel模板的目的是获取数据集并使用Excel的=FORECAST.ETS()
函数。
我想从Excel中获取=FORECAST.ETS()
的值,因此我使用了PHPExcel的GetFormattedValue()
方法。
这是我的代码:
$phpExcel = PHPExcel_IOFactory::load($title);
$objReader = PHPExcel_IOFactory::createReaderForFile($title);
//insert into database forecasted values
$ctr = 0;
while ($ctr != 13){
//set the designate sheets to go to
$sheet1 = $phpExcel ->setActiveSheetIndex($ctr);
$date = $date = date('Y-m-d'); //today's date
$subsegment = $segments[$ctr];
echo "<pre>";
echo $forecastrns = $sheet1->getCell('G2')->GetFormattedValue()." ";
echo $forecastarr = $sheet1->getCell('H2')->GetFormattedValue()." ";
echo $forecastrev = $sheet1->getCell('I2')->GetFormattedValue()." ";
echo "<br/></pre>";
$ctr++;
}
当我打开生成的Excel时,我可以看到使用给定参数成功计算出=FORECAST.ETS()
单元格。但是,当我尝试检索=FORECAST.ETS()
的值时,我得到了这个致命的错误:
致命错误:未捕获的异常'PHPExcel_Calculation_Exception',消息为'RCK!G2 - &gt;公式错误:意外,'在C:\ Users \ Jade Ericson \ Documents \ GitHub \ Forecast-Module-2 \ Prototype \ PHPSCRIPTS \ PHPExcel-1.8 \ Classes \ PHPExcel \ Cell.php:291
堆栈追踪:
#0 C:\ Users \ Jade Ericson \ Documents \ GitHub \ Forecast-Module-2 \ Prototype \ PHPSCRIPTS \ PHPExcel-1.8 \ Classes \ PHPExcel \ Cell.php(189):PHPExcel_Cell-&gt; getCalculatedValue()< / p>
#1 C:\ Users \ Jade Ericson \ Documents \ GitHub \ Forecast-Module-2 \ Prototype \ PHPSCRIPTS \ JASON \ ForecastWithTimespan.php(156):PHPExcel_Cell-&gt; getFormattedValue()
#2 {main}
在第291行的C:\ Users \ Jade Ericson \ Documents \ GitHub \ Forecast-Module-2 \ Prototype \ PHPSCRIPTS \ PHPExcel-1.8 \ Classes \ PHPExcel \ Cell.php中抛出
我也尝试了GetOldCalculatedValue()
方法,但它只返回0
。我想要的只是获得=FORECAST.ETS()
的值。我希望有人可以帮助我。谢谢。