Happening on both PHP7.1 and PHP7.2.
[2017-12-21 22:34:33] acceptance.INFO: ErrorException: count(): Parameter must be an array or an object that implements Countable in /home/forge/website.com/releases/20171221213319/vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php:599
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'count(): Parame...', '/home/forge/acc...', 599, Array)
#1 /home/forge/website.com/releases/20171221213319/vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php(599): count(92)
#2 /home/forge/website.com/releases/20171221213319/vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php(556): Maatwebsite\Excel\Classes\LaravelExcelWorksheet->addData(Array)
#3 /home/forge/website.com/releases/20171221213319/vendor/maatwebsite/excel/src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php(478): Maatwebsite\Excel\Classes\LaravelExcelWorksheet->_addVars(Object(Illuminate\Support\Collection), false, NULL, 'A1', false)
Which version are you using @Jaspur ? Seems like count function is called on non-countable variable. Looks like an easy fix.
Have run into this issue also - running on Laravel 5.5 & PHP 7.2.
I have updated the package to the latest version (2.1.24) which I believe was intended to include a fix for this issue, but apparently it still persists.
Just a bit of further info on this - it's triggered when I run $export->download('xlsx'); but csv works fine.
Okay so from further digging the error I'm encountering actually comes from phpoffice/phpexcel:
/vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Worksheet.php:768
On this line they do:
if (count($columns > 0))
Which is obviously where the route of the issue comes from, if I just swap this to do a simple !empty then it goes through fine.
Update: it only occurs when using ->setAutoFilter()
I can confirm the issue with count(NULL) @andyunleashed mentioned. Since it's happening within an unsupported repository I don't see a clean solution. I used an ugly temporary fix , but there has to be a better way.
Fix in this package was released, fixes needing to happen in PHPExcel, we can't do anything about.
Since PHPExcel was last updated in 2015 I don't see that happening any time soon. Is there anything on the roadmap to move to PHPSpreadsheet which appears to be the successor?
Soonish, but it won鈥檛 be backwards compatible.
...talking about ugly workarounds: I "fixed" this by adding the following to composer.json:
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"sed -i '768s/.*/if(!empty($columns)){/' vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Worksheet.php"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"sed -i '768s/.*/if(!empty($columns)){/' vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/Worksheet.php"
]
It just replaces the faulty line after each composer update or composer install.
@S43534 I dunno what you just did, but I "fixed" it too, whats the side effect ?
I think more proper way of fixing this would be:
composer.json inf forked project so it will have updated project name
"name": "fork-account/phpexcel",
composer.json require section:
"fork-account/phpexcel": "dev-master#LATEST_COMMIT_HASH_WITH_FIX"
repositories to composer.json
"repositories": [
{
"type": "vcs",
"url": "https://github.com/fork-account/phpexcel.git"
}
],
Most helpful comment
...talking about ugly workarounds: I "fixed" this by adding the following to composer.json:
It just replaces the faulty line after each composer update or composer install.