So I'm using PHPExcel in my Laravel project, and in some places I have different formulas, not specified ones, but custom math, like E10*5/E8
etc.
And I get zeros in these cells after download, all the formulas are saved, but are not being pre-calculated.
As far as I understand, I need to set setPreCalculatedFormulas
to true
, but I cannot find the place to insert this line. My code looks as follows:
public function get_excel($id)
{
Excel::create('table_'.$id, function($excel) {
$excel->setCreator("Ana");
$excel->setLastModifiedBy("Ana");
<...>
$excel->sheet('sheet', function($sheet) {
$sheet->setCellValueByColumnAndRow<...>
});
})->download("xsls");
}
And whereever I try to put this setPreCalculatedFormulas, I get an error
LaravelExcelException in LaravelExcelWriter.php line 628: [ERROR] Writer method [setPreCalculateFormulas] does not exist.
Where is my mistake? Would really appreciate any possible help!
UPD: I've changed 'calculate
' and setPreCalculateFormulas
to true in LaravelExcelWriter configs, but the result is still the same.
UPD2: I've tried to add $sheet->getCell("K".$row)->getCalculatedValue();
after inserting a formula, but it did not help
UPD3: predefined formulas like SUM get calculated, but custom ones don't, that's weird
Happy End: I've added Config::set(['excel.export.calculate' => true]);
at the start of my controller, and this one worked out