Reputation: 4151
I am fetching results from database and then creating excel sheet from it.
This stores the file in storage
path.
public function downloadResults(array $filterArr) {
unset($queryArr);
$start = 0;
$limit = 10000;
$response = $this->getFilterResults($filterArr, true, $start, $limit);
$resultHits = $response['resultHits'];
# if results are empty, throw an exception
if($resultHits->isEmpty())
throw new \Exception("No results found for given filter.", 1);
# otherwise continue with the download process...
$exportArr = [];
foreach($resultHits as $key=>$value) {
$list = (array) $value;
array_push($exportArr, $list);
}
$type = 'xls';
$export = Excel::create('result_set_download_'.time(), function($excel) use ($exportArr) {
$excel->sheet('mysheet', function($sheet) use ($exportArr) {
$sheet->fromArray($exportArr);
});
})->store($type, storage_path('app/public/exports'), true);
return $export;
}
If export and store is successful, then stored filename is sent back to browser, else error message is sent.
try {
$exportArr = $this->product->downloadResults($filterArr);
$status = true;
$jsonArr['filename'] = $exportArr['file'];
} catch (\Exception $e) {
$status = false;
$jsonArr['message'] = $e->getMessage();
} finally {
$jsonArr['success'] = $status;
echo json_encode($jsonArr);
}
This is working fine until now, but in case of few exports I get this error:
mysheet!Z2898 -> Formula Error: Unexpected ,
There's not any calculation done while exporting.
I also found a similar post here Laravel Excel Formula Error: Unexpected operator '='
And this is the answer to that post:
// Enable calculation
$reader->calculate();
// Disable calculation
$reader->calculate(false);
But I am confused as to where to put this.
Upvotes: 0
Views: 2070
Reputation: 922
If you want to enable any formula, first export your laravel-excel config
php artisan vendor:publish
Search Maatwebsite then publish it. In my case is 12. Type 12 then Enter.
That will copy a config file to your config folder.
Then from config/excel.php change this line:
excel.php
'pre_calculate_formulas' => true, // default is false
Upvotes: 0